android 高德获取省市,高德地图定位获取当前地址城市街道等详细信息(全部代码)...
自動定位后彈窗信息,包含省市縣鎮區路門牌號(效果圖如下)
代碼↓↓↓
獲取地理位置var mapObj = new AMap.Map('iCenter');
mapObj.plugin('AMap.Geolocation', function () {
geolocation = new AMap.Geolocation({
enableHighAccuracy: true, // 是否使用高精度定位,默認:true
timeout: 10000, // 超過10秒后停止定位,默認:無窮大
maximumAge: 0, // 定位結果緩存0毫秒,默認:0
convert: true, // 自動偏移坐標,偏移后的坐標為高德坐標,默認:true
showButton: true, // 顯示定位按鈕,默認:true
buttonPosition: 'LB', // 定位按鈕停靠位置,默認:'LB',左下角
buttonOffset: new AMap.Pixel(10, 20), // 定位按鈕與設置的停靠位置的偏移量,默認:Pixel(10, 20)
showMarker: true, // 定位成功后在定位到的位置顯示點標記,默認:true
showCircle: true, // 定位成功后用圓圈表示定位精度范圍,默認:true
panToLocation: true, // 定位成功后將定位到的位置作為地圖中心點,默認:true
zoomToAccuracy:true // 定位成功后調整地圖視野范圍使定位位置及精度范圍視野內可見,默認:false
});
mapObj.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, 'complete', onComplete); // 返回定位信息
AMap.event.addListener(geolocation, 'error', onError); // 返回定位出錯信息
});
function onComplete(obj){
var res = '經緯度:' + obj.position +
'\n精度范圍:' + obj.accuracy +
'米\n定位結果的來源:' + obj.location_type +
'\n狀態信息:' + obj.info +
'\n地址:' + obj.formattedAddress +
'\n地址信息:' + JSON.stringify(obj.addressComponent, null, 4);
alert(res);
}
function onError(obj) {
alert(obj.info + '--' + obj.message);
console.log(obj);
}
總結
以上是生活随笔為你收集整理的android 高德获取省市,高德地图定位获取当前地址城市街道等详细信息(全部代码)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows查看linux文件中文,L
- 下一篇: 鸿蒙os能超越ios吗,鸿蒙OS对比iO