By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,256 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,256 IT Pros & Developers. It's quick & easy.

Google Maps JS

100+
P: 384
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??
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2.  
  3.     //<![CDATA[ 
  4.          function createMarker(point,name) { 
  5.          var marker = new GMarker(point,{title:name}); 
  6.          return marker; 
  7.      } 
  8.      function mapclick(ov,pt) { 
  9.          if (marker) map.removeOverlay(marker); 
  10.          if (pt) { 
  11.                          marker = createMarker(pt,pt.toUrlValue()); 
  12.              map.addOverlay(marker); 
  13.          } 
  14.          var match11 = /\(([-.\d]*), ([-.\d]*)/.exec(pt); 
  15.          if (match11) { 
  16.                          var lat = parseFloat( match11[1] ); 
  17.                          var lon = parseFloat( match11[2] ); 
  18.                          lat = lat.toFixed(6); 
  19.                          lon = lon.toFixed(6); 
  20.          } 
  21.          document.getElementById("lat").value = lat; 
  22.          if(document.getElementById("lat").value == "undefined") { 
  23.                          document.getElementById("lat").value = ""; 
  24.          } 
  25.          document.getElementById("lon").value = lon; 
  26.          if(document.getElementById("lon").value == "undefined") { 
  27.                          document.getElementById("lon").value = ""; 
  28.          } 
  29.      } 
  30.      function load() { 
  31.                  if (GBrowserIsCompatible()) { 
  32.                          var map = new GMap2(document.getElementById("map")); 
  33.                          map.setCenter(new GLatLng(53.558584,-7.987061), 6); 
  34.                          map.addControl(new GLargeMapControl()); 
  35.                          var marker = null; 
  36.                          GEvent.addListener(map,"click",function(overlay,point){mapclick 
  37.  (overlay,point)}); 
  38.                  } 
  39.      } 
  40.  
  41.     //]]> 
  42.  </script>   
  43.  
Jan 26 '09 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
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.
Jan 26 '09 #2

100+
P: 384
Got it sorted, got a reply from someone on the gmaps api community.
Jan 26 '09 #3

acoder
Expert Mod 15k+
P: 16,027
So what was the problem/solution in the end?
Jan 26 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.