我正在使用
例如:当我搜索“storms river mouth”时,我会得到一个名为“Storms River Mouth Rest Camp,South Africa”的预测,但是这个地址无法进行地理编码以获取纬度/经度,例如:http://maps.googleapis.com/maps/api/geocode/json?address=Storms%20River%20Mouth%20Rest%20Camp,%20South%20Africa&sensor=true 是否有办法获取自动完成预测的经纬度值?
另外,我不明白为什么Google自动完成返回我无法地理编码的预测。
这是我正在使用的基本逻辑和代码示例:
[编辑] - 在此处查看一个工作示例:http://demos.badsyntax.co/places-search-bootstrap/example.html
google.maps.places.AutocompleteService
来获取地点搜索的建议,但我无法对一些预测进行地理编码。例如:当我搜索“storms river mouth”时,我会得到一个名为“Storms River Mouth Rest Camp,South Africa”的预测,但是这个地址无法进行地理编码以获取纬度/经度,例如:http://maps.googleapis.com/maps/api/geocode/json?address=Storms%20River%20Mouth%20Rest%20Camp,%20South%20Africa&sensor=true 是否有办法获取自动完成预测的经纬度值?
另外,我不明白为什么Google自动完成返回我无法地理编码的预测。
这是我正在使用的基本逻辑和代码示例:
var geocoder = new google.maps.Geocoder();
var service = new google.maps.places.AutocompleteService(null, {
types: ['geocode']
});
service.getQueryPredictions({ input: query }, function(predictions, status) {
// Show the predictions in the UI
showInAutoComplete(predictions);
};
// When the user selects an address from the autcomplete list
function onSelectAddress(address) {
geocoder.geocode({ address: address }, function(results, status) {
if (status !== google.maps.GeocoderStatus.OK) {
// This shouldn't never happen, but it does
window.alert('Location was not found.');
}
// Now I can get the location of the address from the results
// eg: results[0].geometry.location
});
}
[编辑] - 在此处查看一个工作示例:http://demos.badsyntax.co/places-search-bootstrap/example.html