如何在Google地图上放置地标?

时间:2013-09-19 07:03:36

标签: javascript google-maps

如何在Google地图上添加地标?

以下代码仅显示特定位置,但我想在Google地图上添加自定义地点标记图片。

<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=MyKey&sensor=false">
</script>

<script>
function initialize()
{

var mapProp = {
  center:new google.maps.LatLng(23.0300,72.5800),
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
 } 
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>

</body>
</html>

2 个答案:

答案 0 :(得分:5)

以下是Google地图标记示例:

var myMarker = new google.maps.Marker({
position: new google.maps.LatLng(31.1287, -94.9594117), // Example Lat/Long
map: map, // references the map object you defined earlier
title: 'My custom Title', // a title that will appear on hover
    icon: 'images/googleMap/icon-star.gif' // Optional Marker Icon to use
});

您可以在Google Maps: Simple Markers

的Google地图文档中找到更多信息

祝你好运! :)

答案 1 :(得分:2)

试试这个:

<!DOCTYPE html>
    <html>
    <head>
    <script
    src="http://maps.googleapis.com/maps/api/js?key=MyKey&sensor=false">
    </script>

    <script>
    function initialize()
    {
    var mapPin = "/path/to/image.png";
    var Marker = new google.maps.Marker({
      position: new google.maps.LatLng(23.0300,72.5800),
      map: map,
      icon: mapPin
  });
    var mapProp = {
      center:new google.maps.LatLng(23.0300,72.5800),
      zoom:5,
      mapTypeId:google.maps.MapTypeId.ROADMAP
     } 
    var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
    }

    google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    </head>

    <body>
    <div id="googleMap" style="width:500px;height:380px;"></div>

    </body>
    </html>