Jump to content

Clear markers in Google Maps


mikeog

Recommended Posts

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

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...