【发布时间】:2016-11-24 17:04:34
【问题描述】:
我已经在很多网站上搜索了解决方案,但没有一个有效。
从几个小时以来,我一直在尝试使用 latitude 和 longitude 值来获取 城市名称,这些值将从输入框中获取到我的 x, y 变量,但没有示例有效。
我也读过 Google maps API,但没用。
我已经有一个 API 密钥。
你有什么解决办法吗?
这个例子我从网站上得到并尝试但没有成功:
function myFunction() { var x='xxxxx'; var y='xxxxx'; //my coordinates
var geocoder = new google.maps.Geocoder;
var latlng = {lat: parseFloat(x), lng: parseFloat(y)};
geocoder.geocode({'location': latlng}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
// ...
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
【问题讨论】:
-
哇,就是这样,谢谢 :) 喜欢这个网站!
标签: javascript google-maps geolocation latitude-longitude city