Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How do I remove map markers?

I have a list of 'venues' on one page, when a 'venue' is clicked the _id is stored in a lsv and the app navigates to another page.
on this page a read service is invoked using the _id stored in local storage. The response is mapped to various components on the page, one component being a google map.
This works fine.

but if the user leaves the page and clicks another venue, the marker of the previous venue is still shown in the map, as well as the marker for the new venue.

How do I clear the previous map marker before the new marker location is mapped?

I've had a look at these pages but couldn't figure it out:
https://getsatisfaction.com/apperyio/...

https://developers.google.com/maps/do...

Thank you

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How do I remove map markers?

Hi Joe, short answer is that you don't remove the marker from the map ... You take the marker object and tell it to forget what map it is associated with by saying mymarker.map = null ;

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How do I remove map markers?

how do I do this if I have mapped the marker from a service to the component?

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How do I remove map markers?

Joe, I put my markers in a publicly available 'global' array .... So I can have access to them from anywhere....

So in a separate JS asset....

Aofmarkers = [];

In your service:

Aofmarkers.push( onewmarker );

When you need to remove:

Spin through the array setting the map to null.. Using a for construct....

Not sure if that's what you were asking?

Bruce

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How do I remove map markers?

Thank you for your response Bruce.
I'm still not sure what you mean though.

Is there a tutorial on how to do this?

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How do I remove map markers?

Hi Joe,

Let's make sure I understand your problem. You're saying that you don't know how you would set the map associated with the marker to null - because you don't have visibility to the marker object outside of the service where you created the marker correct? ( from your text "....mapped the marker from a service to the component"... )

Bruce

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How do I remove map markers?

Just in case I understand your problem correctly Joe - here are the steps I'd take to implement it visually .... (Im going to be away from my desk for a bit...(

Image

Image

Image

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How do I remove map markers?

Thank you Bruce,
I am away from my desk at the moment but will try implementing this soon.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How do I remove map markers?

Hi Bruce,

I wrote the code as in your example.

I put the last bit of the code on the service success event.

This resulted in the map not working, it doesnt show a marker or position the map the address.

I tired it without the last bit of code and the map still didnt work.

The map worked once I removed the js asset.

not sure what I'm doing wrong.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How do I remove map markers?

any suggestions?

Return to “Issues”