views:

31

answers:

3

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"&gt; 
<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;amp;v=2&amp;amp;sensor=false&amp;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> 
+1  A: 

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!

corroded
+1  A: 

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

var point = new GLatLng(latitude,longitude);
map.addOverlay(new GMarker(point));
gabe3886
would you use an add listener to add text to the marker? By this I mean if someone rolls over the marker I wanted some text to pop up?
shinjuo
+1  A: 

This page should get you going

Jay