h5定位获取城市,街道信息

 <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=bhgBdlyi2yG3On1T6nrpg8vb"></script>
    <script type="text/javascript">
        var map = new BMap.Map("allmap"),
        gc = new BMap.Geocoder;
        function getaddress(c, d) {
            var e = new BMap.Point(d, c),
            f = new BMap.Convertor,
            g = [];
            g.push(e);
            f.translate(g, 1, 5,function(c) {
                gc.getLocation(e,function(c) {
                    var f = c.addressComponents.city;
                    if(f != ''){
                        
                    }
                    $(".location-text").text(f).removeClass("location-no").addClass("location-ok");
                    $("#hidaddress").val(c.addressComponents.city+c.addressComponents.district)
                })
            })
        }
        if(navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(
                function(position) {
                    lng = position.coords.longitude;
                    lat = position.coords.latitude;
                    getaddress(lat,lng);
                },
                function() {

                }
            );
        }
    </script>


打赏

看恩吧
网站不承担任何有关评论的责任
  • 最新评论
  • 总共条评论
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦