jQuery and Google Maps json response

后端 未结 4 1859
庸人自扰
庸人自扰 2021-01-12 21:33

I am having troubles getting geo location info from google maps api

the code is pretty straight forward

$.ajax({
    type: \"GET\",
    cache: false,         


        
4条回答
  •  鱼传尺愫
    2021-01-12 22:06

    Here is a good post on why you were experiencing the behavior from the original question. The URL you are making the request to google at (http://maps.googleapis.com/maps/api/geocode/json) doesn't return a jsonp parseable response, it just returns a raw JSON object. Google refuses to wrap the JSON in the callback supplied.

    The fix for this, more or less from what I can tell, is to make your request to this URL: http://maps.google.com/maps/geo and to include a Google Maps API key in your request. Also there seems to be some necessity in ensuring that the callback parameter in the request is the last parameter of the querystring.

    Here is a jsfiddle of a parseable response from the service (even though it is returning an error because there is no valid Google Maps API key provided): http://jsfiddle.net/sCa33/

    The other option is to do what you have already done, it seems, and use Google's Geocoder object to run the request.

提交回复
热议问题