google map在弹出层中显示经纬度

效果图如下:


 

此处用的弹出层是我播客中前面提到的方法,这里我就不再提出来了。直接说google地址的反向解析问题:

 

需要的js地址:http://maps.google.com/maps?file=api&v=2&amp,也可以直接用此连接。

以下代码就可以实现:

 

 

    var map;

    var geocoder;

    var address;

 

    var webLongitude;

    var webLatitude;

 

 

    function initialize() {

    map = new GMap2(document.getElementById("map_canvas"));

        map.setCenter(new GLatLng(40.730885,-73.997383), 15);

        map.setUIToDefault();

        GEvent.addListener(map, "click", getAddress);

        geocoder = new GClientGeocoder();

      }

 

function getAddress(overlay, latlng) {

     if (latlng != null) {

       address = latlng;

       geocoder.getLocations(latlng, showAddress);

     }

   }

 

   function showAddress(response) {

     map.clearOverlays();

     if (!response || response.Status.code != 200) {

       alert("Status Code:" + response.Status.code);

     } else {

       place = response.Placemark[0];

       point = new GLatLng(place.Point.coordinates[1],

                           place.Point.coordinates[0]);

       marker = new GMarker(point);

       map.addOverlay(marker);

       

                //全局付值, 用于页面需要它的地方获取到

       webLongitude = place.Point.coordinates[1];

       webLatitude = place.Point.coordinates[0];

                

       marker.openInfoWindowHtml(

      

       '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +

       '<b>Address:</b>' + place.address + '<br>' +

       '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +

       '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode );

       

     }

   }

   

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值