mikeog Posted September 5, 2012 Share Posted September 5, 2012 Can anybody tell me how to clear the location marker in Google Maps when the map is centered on a new location? I am useless with JScript so I am struggling. I am using the following script to clear the existing markers (not working) and to display the new position and set the marker (working). TheAddress := Uniedit1.Text; UniSession.AddJS( 'function clearOverlays() {'+ 'if (window.markersArray.length > 0) {'+ 'for (var idx=0;idx<=window.markersArray.length;idx++){'+ 'window.markersArray[idx].setMap(null);'+ '}'+ '}'+ '};'+ 'function codeAddress() {'+ 'var geocoder = new google.maps.Geocoder();'+ 'var address = '+QuotedStr(TheAddress)+';' 'geocoder.geocode( { ''address'': address}, function(results, status) {'+ 'if (status == google.maps.GeocoderStatus.OK) {'+ 'if (typeof googleMap=="object") {googleMap.setCenter(results[0].geometry.location)};'+ 'var marker = new google.maps.Marker({'+ 'map: googleMap,'+ 'position: results[0].geometry.location'+ '});'+ 'window.markersArray.push(marker);'+ 'googleMap.setZoom(18);'+ '} else {'+ 'alert(''Geocode was not successful for the following reason: '' + status);'+ '}'+ '});'+ '};'+ 'clearOverlays();'+ 'codeAddress();' ); The error that I am getting is "Cannot call method setMap of undefined" which suggest that the markersArray is not visible to the function. I have tried adding the global markers array in the HTML of the UniHTMLFrame and as a global variable prior to running the script but I am only going round in circles at this stage. Any suggestions would be appreciated. Mike Quote Link to comment Share on other sites More sharing options...
mikeog Posted September 16, 2012 Author Share Posted September 16, 2012 Just in case anybody else is interested, I tried a variety of "solutions" that I found in online searches and none of them worked. So I gave up on the idea of clearing the markers and simply reloaded a fresh map whenever the location changed. Quote Link to comment Share on other sites More sharing options...
lema Posted September 18, 2012 Share Posted September 18, 2012 Hi Mike. Why not use the: http://forums.unigui.com/index.php?/topic/1225-google-map-new-component/ Quote Link to comment Share on other sites More sharing options...
mikeog Posted October 6, 2012 Author Share Posted October 6, 2012 Hi Lema, I didn't use Patmap's component because I was looking for a simple solution and I didn't particularly want to install a dedicated map component. However, I just looked at the demo of your component and it looks very good. Maybe I will install a map component after all Thanks, Mike Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.