zoukankan      html  css  js  c++  java
  • 高德地图将字符串地址转为经纬度的一个demo

    <!doctype html>
    <html>
    
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
        <title>地理编码</title>
        <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css" />
        <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=25570139c46c9bc652ded0d3be576696&plugin=AMap.Geocoder"></script>
        <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
    </head>
    
    <body onload="geocoder()">
        <div id="container"></div>
        <div id="tip">
    
            <span id="result"></span>
        </div>
        <script type="text/javascript">
            var map = new AMap.Map("container", {
                resizeEnable: true
            });
            
            function geocoder() {
                var geocoder = new AMap.Geocoder({
                    city: "", //城市,默认:“全国”
                    radius: 1000 //范围,默认:500
                });
                //地理编码,返回地理编码结果
                geocoder.getLocation("北京市海淀区苏州街", function (status, result) {
                    if (status === 'complete' && result.info === 'OK') {
                        var start = geocoder_CallBack(result);
                        window.sessionStorage.setItem('start', JSON.stringify(start));
    
                    }
                });
                geocoder.getLocation("深圳大学", function (status, result) {
                    if (status === 'complete' && result.info === 'OK') {
                        var end = geocoder_CallBack(result);
                        var start = JSON.parse(window.sessionStorage.getItem('start'));
                        var locMsg = {
                            startLng: start.lng,
                            startLat: start.lat,
                            endLng: end.lng,
                            endLat: end.lat,
                            startLoc: start.adr,
                            endLoc: end.adr
                        };
                        window.sessionStorage.setItem('locMsg', JSON.stringify(locMsg));
                        console.log(window.sessionStorage.getItem('locMsg'));
                    }
                });
            }
            //地理编码返回结果展示
            function geocoder_CallBack(data) {
                //地理编码结果数组
                var geocode = data.geocodes;
                var obj = {
                    lng: geocode[0].location.lng,
                    lat: geocode[0].location.lat,
                    adr: geocode[0].formattedAddress
                }
                return obj;
            }
    
        </script>
    </body>
    
    </html>
  • 相关阅读:
    [GUIDE] How to Setup Ubuntu 16.04 LTS Xenial Xerus for Compiling Android ROMs
    设置Ubuntu 16.04 LTS的Unity启动器的位置命令
    sed系列:行或者模式匹配删除特定行
    HDOJ 4923 Room and Moor
    Office365client通过本地方式批量部署(即点即用部署)
    hdu 1867 A + B for you again
    Photoshop经常使用快捷键(2)
    SQL_为表和列加凝视
    从头认识java-17.5 堵塞队列(以生产者消费者模式为例)
    Unity5 怎样做资源管理和增量更新
  • 原文地址:https://www.cnblogs.com/songdongdong/p/6783020.html
Copyright © 2011-2022 走看看