开发者

Adding points to google map API

I am putting a google map on my web site and I wanted to add points to the map but I am not sure how to do it. I have tried a few different things but they did not work. Here is what I have so far:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> 
  <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <title>Google Maps JavaScript API Example: Simple Map</title> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=myKeyHere"
            type="text/javascript"></script> 
    <script type="text/javascript"> 

    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(39.8163, -98.55762), 4);
  开发者_运维知识库      map.setUIToDefault();
      }
    }

    </script> 
  </head> 
  <body onload="initialize()" onunload="GUnload()"> 
    <div id="map_canvas" style="width: 750px; height: 500px"></div> 
  </body> 
</html> 


This page should get you going


The Google Maps API shows information on how to do this. Basically do:

var point = new GLatLng(latitude,longitude);
map.addOverlay(new GMarker(point));


I used this plugin (it uses Google Map V3 as V2 is deprecated)

http://blog.bobcravens.com/2010/06/06/AGoogleMapsVersion3JQueryPlugin.aspx

it also requires jquery(which makes things easier). It has methods such as

map.addMarkerByLatLng

or

map.addMarkerByAddress

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜