Refresh/Reload maps : Google maps API V2
Asked Answered
T

3

6

I'm showing some marker in my google map retrieving some points from database. Here I can add some new points or remove some points in my database as well. But my problem is when new points are added to the database, the map does not show the updated points into the map since it is not refreshed. I don't want to refresh the entire web page. Here is the link of my work -

http://128.233.104.33/passgui/editLeveledit.php

What I want is -

--to show the newly added data on the map when I click add new POIs

--If I delete a single POI should also be removed from the map once delete POI button is clicked from the level table.

Can anyone help me out please?

Til answered 27/7, 2011 at 23:0 Comment(3)
thank's for the bounty, i don't want to bother you, but you should also check the answer in order to fully accept it. if you have any other question about the code, just let mw know, regards ;-)Totipalmate
Thanks for the comment. Sure I'll do that. It's getting a little late since I'm busy with some other projects these days. Will do it ASAP. Please don't remove it from your server. Thanks a lot for your help.Til
don't warry the demo will be there! ;-)Totipalmate
G
0

A good strategy would be to store all your current gmarker into a javascript array. First if you delete or add a new gmarker you delete or add this to your array and then you delete every gmarker on then map (clear map) and then you want to loop through your array and redraw each gmarker if a delete or add onClick-event is fired.

Gunrunning answered 30/7, 2011 at 10:13 Comment(0)
L
0

Here is an extensive reference for the Google Maps v2 API: http://econym.org.uk/gmap/

Look at "Part 11" from "The basics". Points are deleted / added upon click on buttons. New coordinates are retrieved using Ajax, bit I'm sure you can manage another way. :-)

Lonni answered 30/7, 2011 at 12:32 Comment(0)
T
0

DEMO: http://so.devilmaycode.it/refresh-reload-maps-google-maps-api-v2/


all you need is inside the source, take a look and let me know.

basically the demo make use of the markermanager.js lib, just like you do now, it explane how to reference to new added markers and how to insert and remove them without refreshing the current map/page;

the process behind is simple, each time a marker is added to the map by using the addMarkers func it create a marker.object, the property we are looking for is marker.no that is in form of marker# where # is the incremental number so can be any digit.

now, the real trick here is to create a global array where we store all the created markers for easy access.

So, we can reach and delete each single marker by using the removeMarker func like this: removeMarker(global_marker_array[marker_id]); where marker_id is the marker.no;

i think this approach is really nice cause you don't need to know the lat and long for retrieve the markers a second time.

Totipalmate answered 5/8, 2011 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.