如何?在H5裡調起高德地圖APP

來源:互聯網
上載者:User

標籤:play   user   效果   UI   json對象   ntb   asc   實現   1.0   

點標記位置展示

通常我們都使用Marker點來進行位置的標定,所以JSAPI在Marker類中提供了markOnAMAP的方法,這個方法接受一個JSON對象參數,參數對象包含position和name兩個屬性,調起之後將在高德地圖用戶端或者Web網站標記顯示對應的Marker點,基於marker點的展示,使用者可以接著使用周邊搜尋、路線規劃和導航等功能。掃描右側二維碼,點擊地圖中見的marker點查看移動端調起來效果。

 

核心代碼:

var marker = new AMap.Marker({
        position:[116.473188,39.993253]
    });

    marker.markOnAMAP({
        position: marker.getPosition(),
        name:‘首開廣場‘//name屬性在移動端有效
    })

全部原始碼,可複製後直接使用:

<!DOCTYPE html>
<html>
<head lang="en">
    <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>
    <style>
        body,#mapContainer{
            margin:0;
            height:100%;
            width:100%;
            font-size:12px;
        }
    </style>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main.css?v=1.0?v=1.0" />
    <script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=您申請的key值&plugin=AMap.ToolBar"></script>
    <script>
        function init() {
            map = new AMap.Map("mapContainer", {
                zoom: 18,
                center:[116.473188,39.993253]
            });
            marker = new AMap.Marker({
                map:map,
                position:[116.473188,39.993253]
            })
            marker.setLabel({
                offset: new AMap.Pixel(20, 20),//修改label相對於maker的位置
                content: "點擊Marker開啟高德地圖"
            });
            marker.on(‘click‘,function(e){
                marker.markOnAMAP({
                    name:‘首開廣場‘,
                    position:marker.getPosition()
                })
            })
            map.addControl(new AMap.ToolBar());
            if(AMap.UA.mobile){
                document.getElementById(‘button_group‘).style.display=‘none‘;
            }
        }
    </script>
</head>
<body onload="init()">
    <div id="mapContainer" ></div>
    <div class="button-group" id=‘button_group‘ style=‘top:15px;bottom:inherit‘>
        <img src="http://a.amap.com/lbs/static/img/markonapp.png" style=‘width:120px;height:120px‘>
        <div class=‘button‘ style=‘text-align: center‘>手機掃碼開啟demo</div>
    </div>
</body>
</html>

如何?在H5裡調起高德地圖APP

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.