SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding a marker to Google maps

    How do you add a marker to a Google map? I know it has something to do with map.addOverlay(marker), but what value should marker be? Here's what I've got so far:

    Code JavaScript:
        <script type="text/javascript">
            function load() {
                if (GBrowserIsCompatible()) {
                      var map = new GMap2(document.getElementById ("map"));  
                      map.addControl(new GSmallMapControl());
                      map.setCenter(new GLatLng(-27.462719, 153.029122), 16);
                }
              }
        </script>

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var point1 = new GMarker(new GLatLng(38, -97));
    map.addOverlay(point1);
    
    var point2 = new GMarker(new GLatLng(40, -95));
    map.addOverlay(point2);

  3. #3
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually just got it working this way:

    Code JavaScript:
        var geocoder;
        var map;
        var address = "Brisbane, QLD 4000, Australia";
        function load() {
            map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            geocoder = new GClientGeocoder();
            geocoder.getLocations(address, addToMap);
        }
     
        function addToMap(response) {
            place = response.Placemark[0];
            point = new GLatLng(place.Point.coordinates[1],
            place.Point.coordinates[0]);
            map.setCenter(point, 16);
            marker = new GMarker(point);
            map.addOverlay(marker);
        }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •