@@ -10,6 +10,7 @@ import 'utils.dart';
10
10
part 'places.g.dart' ;
11
11
12
12
const _placesUrl = '/place' ;
13
+ const _geocodeUrl = '/geocode/json' ;
13
14
const _nearbySearchUrl = '/nearbysearch/json' ;
14
15
const _textSearchUrl = '/textsearch/json' ;
15
16
const _detailsSearchUrl = '/details/json' ;
@@ -126,6 +127,23 @@ class GoogleMapsPlaces extends GoogleWebService {
126
127
return _decodeDetailsResponse (await doGet (url, headers: apiHeaders));
127
128
}
128
129
130
+ /// Returns lat and lng of a place
131
+ Future <GeocodeResponse > cgetGeoodeByPlaceId (
132
+ String placeId, {
133
+ String ? sessionToken,
134
+ List <String > fields = const [],
135
+ String ? language,
136
+ String ? region,
137
+ }) async {
138
+ final url = buildGeocodeUrl (
139
+ placeId: placeId,
140
+ sessionToken: sessionToken,
141
+ language: language,
142
+ region: region,
143
+ );
144
+ return _decodeGeocodeResponse (await doGet (url, headers: apiHeaders));
145
+ }
146
+
129
147
@deprecated
130
148
Future <PlacesDetailsResponse > getDetailsByReference (
131
149
String reference, {
@@ -380,6 +398,41 @@ class GoogleMapsPlaces extends GoogleWebService {
380
398
.toString ();
381
399
}
382
400
401
+ String buildGeocodeUrl ({
402
+ required String placeId,
403
+ String ? sessionToken,
404
+ String ? language,
405
+ String ? region,
406
+ }) {
407
+ final params = < String , String > {};
408
+
409
+ params['placeid' ] = placeId;
410
+
411
+
412
+ if (language != null ) {
413
+ params['language' ] = language;
414
+ }
415
+
416
+ if (region != null ) {
417
+ params['region' ] = region;
418
+ }
419
+
420
+ if (apiKey != null ) {
421
+ params['key' ] = apiKey! ;
422
+ }
423
+
424
+ if (sessionToken != null ) {
425
+ params['sessiontoken' ] = sessionToken;
426
+ }
427
+
428
+ return url
429
+ .replace (
430
+ path: '${url .path }$_geocodeUrl ' ,
431
+ queryParameters: params,
432
+ )
433
+ .toString ();
434
+ }
435
+
383
436
String buildAutocompleteUrl ({
384
437
required String input,
385
438
String ? sessionToken,
@@ -527,6 +580,9 @@ class GoogleMapsPlaces extends GoogleWebService {
527
580
PlacesDetailsResponse _decodeDetailsResponse (Response res) =>
528
581
PlacesDetailsResponse .fromJson (json.decode (res.body));
529
582
583
+ GeocodeResponse _decodeGeocodeResponse (Response res) =>
584
+ GeocodeResponse .fromJson (json.decode (res.body));
585
+
530
586
PlacesAutocompleteResponse _decodeAutocompleteResponse (Response res) =>
531
587
PlacesAutocompleteResponse .fromJson (json.decode (res.body));
532
588
}
@@ -926,6 +982,29 @@ class PlacesDetailsResponse extends GoogleResponseStatus {
926
982
Map <String , dynamic > toJson () => _$PlacesDetailsResponseToJson (this );
927
983
}
928
984
985
+ @JsonSerializable ()
986
+ class GeocodeResponse extends GoogleResponseStatus {
987
+ final Geometry result;
988
+
989
+ /// JSON html_attributions
990
+ @JsonKey (defaultValue: < String > [])
991
+ final List <String > htmlAttributions;
992
+
993
+ GeocodeResponse ({
994
+ required String status,
995
+ String ? errorMessage,
996
+ required this .result,
997
+ required this .htmlAttributions,
998
+ }) : super (
999
+ status: status,
1000
+ errorMessage: errorMessage,
1001
+ );
1002
+
1003
+ factory GeocodeResponse .fromJson (Map <String , dynamic > json) =>
1004
+ _$GeocodeResponseFromJson (json);
1005
+ Map <String , dynamic > toJson () => _$GeocodeResponseToJson (this );
1006
+ }
1007
+
929
1008
@JsonSerializable ()
930
1009
class Review {
931
1010
/// JSON author_name
0 commit comments