3

如何在谷歌地图上放置地标?

下面的代码仅显示特定位置,但我想在谷歌地图上添加我的自定义地标图像。

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

2 回答 2

5

这是一个示例谷歌地图标记:

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 地图的 Google 地图文档中找到更多信息:简单标记

祝你好运!:)

于 2013-09-19T07:12:06.070 回答
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>
于 2013-09-19T07:09:34.157 回答