facebook

How to remove markers on a map

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #343812 Reply

    Hi,

    I’m having a small issue on my map. When I go to the map it place correctly a new marker (from lat,lng from a list). Each time I go to the mapscreen, the markers set previous is still there… How do I delete all previous markers when entering the mapscreen.

    Cheers
    TKT

    #343825 Reply

    Funci
    Participant

    Hi TKT,

    Maybe something like in this topic with SetMap(null)?

    http://www.genuitec.com/support-genuitec/viewtopic.php?f=8&t=5183&hilit=polyline

    #343838 Reply

    Hi Funci,

    thanks for your suggestion.

    I’ve been trying to solve it, but I’m not quite sure that’s the problem. The first time I go to the map screen the markers are placed and work just fine. If I navigate around the map (move it) leave the screen and come back – the map is not centered to my location as the first time. Seems like the page are cached or something, but I’ve checked the “No offline support”.

    I would like the screen to refresh, each time I enter it.

    #343843 Reply

    Funci
    Participant

    Yes… I’ve noticed the same thing in my project, but I can set center of the page when coming back from another screens by some parameters…
    Maybe you can dynamicly save in some variable centered location of the map before you leave that screen and on returning set center again on that coordinates?

    #343847 Reply

    Unknown Author
    Participant

    Remember: You’re pushing and poping markers from an array. So, you need to clear the array and reset its length.

    Here’s what I use to delete overlays.

    
    function deleteOverlays(){
     if (markersArray) {
      for (i in markersArray){
       markersArray[i].setMap(null);
       }
      markersArray.length = 0;
      }
    }
    

    For more fun with GoogleMaps, check out my app, Proximal, on iTunes:
    https://itunes.apple.com/us/app/proximal/id572222453?mt=8

    -1TC

    #344340 Reply

    Thank you thin chip,

    However I’ve been on a vacation, and apparently for to long time, because I can not get my brain to work right :-/

    Im adding the markers like this:

    //
    if(parm=='mypos'){
        mapoptions = {position:pos,
                      map:gmap,
                      animation:google.maps.Animation.DROP, //BOUNCE,
                      title: itemhead,
                      timeout:300,
                      clickable: true};
             
         var marker = new google.maps.Marker(mapoptions) 
         var infowindow = new google.maps.InfoWindow({
          content: itemhead
         });
    
         google.maps.event.addListener(marker, 'click', function() {
           infowindow.open(gmap,marker);
         });
      }
    //

    I’ll be very greatfully if you could tell me exactly how the syntax be to remove them, in that case.

    Thank you
    Torben

    #344375 Reply

    Unknown Author
    Participant

    I will not write your app for you.

    -1TC

    #344381 Reply

    Hi 1thinchip,

    fair enough 🙂

    I guess I just have to skip long vacations in the future then…

    #344430 Reply

    Okay Anyone – I can’t get rid of these fuc….ig markers.

    I’ve tried the solutions posted here – I’ve read the google API – I still can’t figure it out!

    can anyone please help me.

    Where do I put the setMap(null)

    regards
    TKT

    #344431 Reply

    support-michael
    Keymaster

    Did you take a look at this example https://developers.google.com/maps/documentation/javascript/examples/marker-remove

    Does the marker removal problem only occur when you move to another screen and then return?

    #344441 Reply

    Hi support-wayne,

    Yes I’ve looked at this also. But I don’t understand why I can see the markers without using “markers.push(marker)” – that means that the markers is not in an array or?

    I’ve been using this example when I started on this project.
    https://docs.google.com/document/d/1lAKCcL11tonv8lzxgZXCbBYloNWUkjr0FltJozQ6cR8/edit

    The problem is that I have a list with different lat & lng, when I click an item on this list, I go to the map screen which shows a pin gfor the position I’ve just clicked. When I go back to the list and click a new item, the previous marker is still there. Eg. if I’ve clicked 12 items on the list, the map will show 12 markers.

    I want the map only to show the marker for the item I’ve clicked.

    Does this make sense?

    Regards
    TKT

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: How to remove markers on a map

You must be logged in to post in the forum log in