• 通过GMAP得到坐标对应地址


    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
    <div id='mapZone' style="500px;height:300px;"></div>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script>
        console.log(google.maps);
        
    var ddd = new google.maps.Geocoder();
        
    //position.coords.latitude position.coords.longitude
        var latlng = new google.maps.LatLng(25.0392,121.525002);
        ddd.geocode({
            
    'address''布吉'//根据地址得到坐标等信息
        },function(data){
            console.log(data);
        })
        ddd.geocode({
            
    'latLng': latlng//根据坐标得到地址等信息
        },function(data){
            console.log(data);
        })
    function getPositionSuccess(position){
        
    var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        
    var myOptions = {//绘制地图
            zoom: 15,
            center: latlng,
            mapTypeControl: 
    false,
            navigationControlOptions: {
                style: google.maps.NavigationControlStyle.SMALL
            },
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        
    var map = new google.maps.Map(document.getElementById("mapZone"), myOptions);
        
    var marker = new google.maps.Marker({
            position: latlng,
            map: map
        });
        
    var infowindow = new google.maps.InfoWindow();//弹出窗口
        infowindow.setContent("You are here!");
        infowindow.setPosition(latlng);
        infowindow.open(map);
    }
    function getPositionError(error){
        console.log(error);
        
    switch (error.code) {
            
    case error.TIMEOUT:
                alert(
    " 连接超时,请重试 ");
                
    break;
            
    case error.PERMISSION_DENIED:
                alert(
    " 您拒绝了使用位置共享服务,查询已取消 ");
                
    break;
            
    case error.POSITION_UNAVAILABLE:
                alert(
    " 亲爱的火星网友,非常抱歉,我们暂时无法为您所在的星球提供位置服务 ");
                
    break;
        }
    }
    if (navigator.geolocation) {//得到浏览器坐标
        navigator.geolocation.getCurrentPosition(getPositionSuccess, getPositionError);
    }
    else {
        alert(
    "你的浏览器不支持geolocation哦~");
    }

    </script>
    </body>
    </html>
  • 相关阅读:
    關于招聘新人
    JS在线打字练习 PHP
    useragent 分析 PHP
    webSql工具 PHP
    《网站开发人员应该知道的61件事》[解读] PHP
    HTMLCSS速查 PHP
    Flash文字转图片 PHP
    Flash简易文件上传 PHP
    Google 字体 API PHP
    Google 二维条码 API PHP
  • 原文地址:https://www.cnblogs.com/liushannet/p/2600929.html
Copyright © 2020-2023  润新知