zoukankan      html  css  js  c++  java
  • 通过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>
  • 相关阅读:
    堆排序
    如何在.Net中使用MongoDB
    二叉树遍历 C#
    对C# 中Readonly的再认识
    对C# 构造函数的理解
    TypeScript学习: 九、TypeScript的泛型
    TypeScript学习: 八、TypeScript的属性接口用法封装ajax
    锚点跳转不改变History
    设计模式笔记—代理模式
    小程序开发二:上手第一个小程序
  • 原文地址:https://www.cnblogs.com/liushannet/p/2600929.html
Copyright © 2011-2022 走看看