Delusional Logic
Delusional Logic

Reputation: 828

Fetching place from location

If i have the longitude and latitude of a location i can use reverse geocoding to get basic information about a location (Like the address), but i want more information. I'm using the Places API for a search-bar, and that returns a huge amount of data, but i can't get a place from a Latitude and longitude.

I've found that the places API supports place details, but for that i need a reference which i can't get from anywhere.

Note: I'm writing this in dart, but the dart api is just a wrapper around javascript, which is why i tagged this as both.

Upvotes: 1

Views: 195

Answers (2)

Delusional Logic
Delusional Logic

Reputation: 828

I ended up going with the PlaceService.textSearch route. This was not nearly as dirty as i expected. The function i ended up with looks like this:

void placeFromLocation(LatLng location, void callback(PlaceResult)) {
    GeocoderRequest geocoderRequest = new GeocoderRequest()
        ..location = location;
    geocoder.geocode(geocoderRequest, (List<GeocoderResult> results, GeocoderStatus status) {
        if(status == GeocoderStatus.OK) {
            TextSearchRequest request = new TextSearchRequest()
                ..query = results[0].formattedAddress
                ..location = results[0].geometry.location
                ..radius = 40;
            placeService.textSearch(request, (List<PlaceResult> results, PlacesServiceStatus status) {
                if(status == PlacesServiceStatus.OK) {
                    callback(results[0]);
                }else{
                    print("Not place found");
                }
            });
        }else{
            print("Error geocoding address");
        }
    });
}

Upvotes: 1

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76343

The PlaceResult object contains an reference attribute that should be used in PlaceDetailsRequest provided to PlacesService.getDetails.

Upvotes: 1

Related Questions