Google Maps JS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    Google Maps JS

    I'm not sure if anyone here would know anything about the google map js, i've tried the google maps api community with no luck.

    I have the below code, it loads ok, but when i click on the map it
    doesn't place a marker.
    What should happen is that when you click on the map it should place a
    marker and when clicked on the map a second time that it should place
    a marker at the new location and remove the previous one so that there
    is only ever one marker on the map??
    Code:
    <script type="text/javascript"> 
     
        //<![CDATA[ 
             function createMarker(point,name) { 
             var marker = new GMarker(point,{title:name}); 
             return marker; 
         } 
         function mapclick(ov,pt) { 
             if (marker) map.removeOverlay(marker); 
             if (pt) { 
                             marker = createMarker(pt,pt.toUrlValue()); 
                 map.addOverlay(marker); 
             } 
             var match11 = /\(([-.\d]*), ([-.\d]*)/.exec(pt); 
             if (match11) { 
                             var lat = parseFloat( match11[1] ); 
                             var lon = parseFloat( match11[2] ); 
                             lat = lat.toFixed(6); 
                             lon = lon.toFixed(6); 
             } 
             document.getElementById("lat").value = lat; 
             if(document.getElementById("lat").value == "undefined") { 
                             document.getElementById("lat").value = ""; 
             } 
             document.getElementById("lon").value = lon; 
             if(document.getElementById("lon").value == "undefined") { 
                             document.getElementById("lon").value = ""; 
             } 
         } 
         function load() { 
                     if (GBrowserIsCompatible()) { 
                             var map = new GMap2(document.getElementById("map")); 
                             map.setCenter(new GLatLng(53.558584,-7.987061), 6); 
                             map.addControl(new GLargeMapControl()); 
                             var marker = null; 
                             GEvent.addListener(map,"click",function(overlay,point){mapclick 
     (overlay,point)}); 
                     } 
         } 
     
        //]]> 
     </script>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If you can't even get a marker to show up, then you should perhaps take a simple example (Google Maps API Examples - Google Maps API - Google Code) and adapt it.

    Comment

    • ziycon
      Contributor
      • Sep 2008
      • 384

      #3
      Got it sorted, got a reply from someone on the gmaps api community.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        So what was the problem/solution in the end?

        Comment

        Working...