0
我試圖對地址進行地址解析,在這種情況下,Google地址是HQ。解析從Google Maps API返回的JSON
當我試圖讓jQuery的$.ajax()
請求得到JSON,它說:未捕獲的SyntaxError:意外的標記:我好像
無法揣摩出意外:是。我想要做的是將地址作爲一個字符串解碼lat和long,並使用Places API找到這些座標附近的機制。
$.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);
});
'var place = mapResultsi];'應該是'var place = mapResults [i];' – 2014-10-01 21:08:24
''location:new google.maps.LatLng(queryLat,queryLong)'' – 2014-10-01 21:13:46
@PaulRoub謝謝。 – wordSmith 2014-10-01 21:15:12