|
|
 - <div id='container'></div>
- <script type="text/javascript" src="//webapi.amap.com/maps?v=1.4.15&key={$settings['gdmapkey']}"></script>
- <script>
- //高德地图定位API
- var map = new AMap.Map('container', {
- resizeEnable: true
- });
- map.plugin('AMap.Geolocation', function() {
- var geolocation = new AMap.Geolocation({
- // 是否使用高精度定位,默认:true
- enableHighAccuracy: true,
- // 设置定位超时时间,默认:无穷大
- timeout: 5000,
- // 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
- buttonOffset: new AMap.Pixel(10, 20),
- // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
- zoomToAccuracy: true,
- // 定位按钮的排放位置, RB表示右下
- buttonPosition: 'RB'
- });
- geolocation.getCurrentPosition(function(status,result){
- if(status == 'complete'){
- //console.log(result);
- var params = {
- country: result.addressComponent.country,
- province: result.addressComponent.province,
- city: result.addressComponent.city,
- district: result.addressComponent.district,
- lat: result.position.lat,
- lng: result.position.lng
- }
- $("input[name='country']").val(params.country);
- $("input[name='province']").val(params.province);
- $("input[name='city']").val(params.city);
- $("input[name='district']").val(params.district);
- $("input[name='lat']").val(params.lat);
- $("input[name='lng']").val(params.lng);
- }else{
- //console.log(result);
- }
- });
- });
- </script>
复制代码
|
|