1

我正在使用 jQuery 文档中的示例代码

<div data-role="popup" id="popupMap" data-overlay-theme="a" data-theme="a" data-corners="false" data-tolerance="15,15">

    <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>

    <iframe src="map.html" width="480" height="320" seamless></iframe>

</div>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Map</title>
    <script>
        function initialize() {
            var myLatlng = new google.maps.LatLng( 51.520838, -0.140261 );
            var myOptions = {
                zoom: 15,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            var map = new google.maps.Map( document.getElementById( "map_canvas" ), myOptions );
        }
    </script>
    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <style>
        html {
            height: 100%;
            overflow: hidden;
        }
        body {
            margin: 0;
            padding: 0;
            height: 100%;
        }
        #map_canvas { 
            height: 100%;
        }    
    </style>
</head>
<body onload="initialize()">

    <div id="map_canvas"></div>

</body>
</html>

这会在屏幕的弹出窗口中打开谷歌地图。

但是,我怎样才能在特定位置放置一个大头针来完成这项工作呢?

4

1 回答 1

1

此代码将在 -25.363882、131.044922 的位置向您的地图添加一个标记:

function initialize() {
    var myLatlng = new google.maps.LatLng( 51.520838, -0.140261 );
    var myOptions = {
        zoom: 15,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map( document.getElementById( "map_canvas" ), myOptions );
    var markerLatlng = new google.maps.LatLng(-25.363882,131.044922);
    var marker = new google.maps.Marker({
        position: markerLatlng,
        title:"Hello World!"
    });
    marker.setMap(map);
}

我真的鼓励您阅读Google Maps API 指南

于 2012-12-03T09:26:08.697 回答