2012-12-03 51 views
1

我使用jQuery的從文件jQuery Mobile的,如何將針添加到谷歌地圖

<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> 

示例代碼,這打開了谷歌地圖在一個彈出窗口在屏幕上。

但是,我怎樣才能使這項工作與銷在特定位置下降?

回答

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 Guide