Reputation: 3183
I'm trying to geocode an address, in this case, Google's HQ.
When I try to make the jQuery $.ajax()
request to GET the JSON, it says Uncaught SyntaxError: Unexpected token :
I can't seem to figure out where the unexpected : is. What I'm trying to do is decode the lat and long from an address as a string and use the Places API to find mechanics near those coordinates.
$.ajax({
url: 'https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=myKey',
dataType: 'jsonp',
jsonp: 'callback',
method: 'GET',
success: function(results){
console.log(results);
queryLat = results['results']['geometry']['location']['lat'];
queryLong = results['results']['geometry']['location']['lng'];
console.log('latitude: '+queryLat);
console.log('longitude: '+queryLong);
function callback(mapsResults, status){
if(status == google.maps.places.PlacesServiceStatus.OK){
for(var i = 0; i < mapResults.length; i++){
var place = mapResultsi];
createMarker(mapResults[i]);
}
}
}
var map;
var service;
map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(queryLat, queryLong),
zoom: 15
});
var request ={
location: new google.maps.LatLng(queryLat, queryLong)
radius:'500',
query:'mechanic'
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
});
Upvotes: 0
Views: 715
Reputation: 36438
Three problems:
$.ajax()
to expect jsonp
when you're calling a JSON-returning APIvar place = mapResultsi];
should be var place = mapResults[i];
location: new google.maps.LatLng(queryLat, queryLong)
Upvotes: 1
Reputation: 36703
function callback(mapsResults, status){
if(status == google.maps.places.PlacesServiceStatus.OK){
for(var i = 0; i < mapResults.length; i++){
**var place = mapResultsi];**
createMarker(mapResults[i]);
}
}
}
Upvotes: 0