『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

Google Map输入地址转换经纬度

Google Map输入地址转换经纬度
之前,写过两篇文章,关于在Google Map中将经纬度转换成地址。Google map geocode服务将经纬度转换成具体地址(js)这里面利用的是jquery发送反向地址解析请求,然后利用jquery来解析返回的json,这种方法过于繁琐。

       之前,写过两篇文章,关于在Google Map中将经纬度转换成地址。Google map geocode服务将经纬度转换成具体地址(js)这里面利用的是jquery发送反向地址解析请求,然后利用jquery来解析返回的json,这种方法过于繁琐。后来在Google Map另外一种方法实现经纬度转换成具体地址(google.maps.Geocoder)中,用Google Map原生的方法实现了反向地址解析,也就是经纬度转换成地址。

 

       本文实现的是地址转换经纬度,即地址解析。

 

       效果如图:

 

 

 

      关键代码:

 

$("#btn_sub").click(function(){//jQuery捕获点击动作

    myplace=$("#input_val").val();//获取输入的地址

    var geocoder = new google.maps.Geocoder();//创建geocoder服务

    /* 调用geocoder服务完成转换 */

    geocoder.geocode( { 'address': myplace}, function(results, status) {

    if (status == google.maps.GeocoderStatus.OK) {

        map.setCenter(results[0].geometry.location);

        marker = new google.maps.Marker({

            map: map,

            position: results[0].geometry.location

        });

        infowindow = new google.maps.InfoWindow({

            content: results[0].geometry.location.lat()+' , '+results[0].geometry.location.lng(),

            maxWidth: 200

        });

        google.maps.event.addListener(marker, 'click', function() {

            infowindow.open(map,marker);

        });

    } else {

        alert('Geocode was not successful for the following reason: ' + status);

    }

    });

});

 

 

       说明:

 

      其实这也是调用了Google Mapgeocoder服务,跟上一篇文章中用的服务一致,只是参数换了而已。

 

       后话:

 

       还有一种简单方法,在浏览器中输入

 

       http://maps.google.com/maps/api/geocode/json?address=杭州&language=zh-CN&sensor=false

 

       将会出现杭州的经纬度信息。

 

       或者在浏览器中输入

 

        http://maps.google.com/maps/api/geocode/json?latlng=30,120&language=zh-CN&sensor=false

 

        将会出现30,120对应的地址。

      京ICP备2025132830号-1 京公网安备 号