google-geocoding-api - 从 LatLong 获取确切地址
问题描述
我一直在尝试使用地理编码获取移动设备的确切地址。
这是我的代码
function showPosition(position) {
debugger;
console.log("Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude);
CLat = position.coords.latitude;
Clng = position.coords.longitude;
add = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + CLat + "," + Clng + "&key=" + _globalAPIKey;
console.log(add);
var geocoder = new google.maps.Geocoder();
var latLng = new google.maps.LatLng(CLat, Clng);
if (geocoder) {
debugger;
geocoder.geocode({ 'latLng': latLng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
debugger;
console.log(results[0].formatted_address);
alert('Address:' + results[0].formatted_address);
}
else {
debugger;
//alert('Geocoding failed: ' + status);
console.log("Geocoding failed: " + status);
}
}); //geocoder.geocode()
}
}
在这里,我得到了地址,但它不是确切的地址。我可以指定边界或范围,以便我可以得到确切的地址。
或者我没有得到准确的 LatLog ,因为 Address 也是错误的。
请提供您的建议或示例代码。
感谢和问候 Rahul K Sharma
解决方案
推荐阅读
- azure - 是否可以使用 MSAL 获取 Azure AD V1 令牌?
- android - 异步任务完成后如何刷新片段中的列表视图?
- c# - 如何使用 C# 添加带有文本和图标的 Excel 行命令栏标题
- sql - SUBSTRING 中的 CHARINDEX 减法不起作用
- acumatica - 如何使用 PXCustomizeBaseAttribute 自定义 PXSelector
- dynamics-crm - 隐藏全局菜单(命令)栏中的按钮
- c# - C# 正则表达式可选 url 参数
- assembly - 如果我在 x86 中更改堆栈指针,基指针是否会更改?
- c - 后缀 C 程序的中缀
- javascript - ScrollIntoView 滚动到页面底部而不是块的开头