Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places API get details - Invalid Request

So I'm trying to get details based on a google places text search. My text search is working fine, but to get details I keep getting "Invalid Request".

I've followed examples from the documentation, as well as examples from other people but to no avail, I have failed....

This is my text search, which is working.

var lat = '43.09182244507046'
var lng = '-89.48985488807972'
var places;
    function initialize() {


        var location = new google.maps.LatLng(lat,lng);

        var map = new google.maps.Map(document.getElementById('map'),{
            center: location,
            zoom: 15
        });

        var request = {
            location: location,
            radius: '50000',
            query: 'food'
        };

        var callback = function (results, status) {
                places = results;
              console.log(status);
              console.log(places);
        }

        var service = new google.maps.places.PlacesService(map);
        service.textSearch(request, callback);

    }

This is my place details search which is getting an Invalid Request status

var place_details;
        function getDetails() {

            var location = new google.maps.LatLng(lat,lng);

            var map = new google.maps.Map(document.getElementById('map'),{
                center: location,
                zoom: 15
            });

            var callback = function (results, status) {
                place_details = results;
            };

            var service = new google.maps.places.PlacesService(map);
            service.getDetails({
                placeId: "8deae188679ff8b9344085de5360a769879240f9"}, function(place, status){
                   place_details = place;
                    console.log(place_details);
                    console.log(status);
                }
            );
        }

I had the if(status === google.maps.places.PlaceService.OK) in there. So that's not the issue in case anyone catches that.

Any help would be appreciated... I want this to work!

like image 799
Anthony Urbina Avatar asked Apr 19 '16 06:04

Anthony Urbina


1 Answers

8deae188679ff8b9344085de5360a769879240f9 is not a Place ID. I suspect you're using PlaceResult.id which doesn't work with details requests and is deprecated.

Instead use PlaceResult.place_id. See the documentation for details and examples.

like image 90
spiv Avatar answered Sep 28 '22 03:09

spiv