Lewis Johnson5536249
Posts: 0
Joined: Mon Feb 11, 2013 2:51 pm

Multiple Google Map Markers from REST request

Does someone have a good working example to show multiple map markers which they have returned from a REST request? If so would you mind sharing how best to achieve it?

I've searched the forum and can't really find a consistent way of doing it. My longitude and latitude data is held in separate fields in the DB - see imageImage

many thanks for any help anyone can give

Lewis

Lewis Johnson
Posts: 0
Joined: Tue Jan 29, 2013 12:58 pm

Multiple Google Map Markers from REST request

many thanks, this is the post that i have been working from and can get most things working where the points are contained directly in the javascript.

What i'm struggling with is converting the final javascript extension to fit my REST response data. I know the data is returned as i can map it to a list box. I'm just struggling with capturing the array details into the javascript and then using that to create the markers...

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Multiple Google Map Markers from REST request

What I do is Make an array. Push (add) each lat long then Json.stringify to LocalStorage.

Then on the map screen. JSON.parse the LocalStorage and use for loop to extract each array item and display locations via InfoWindow on maps.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Multiple Google Map Markers from REST request

We will search for solution and I'll update.

Lewis Johnson
Posts: 0
Joined: Tue Jan 29, 2013 12:58 pm

Multiple Google Map Markers from REST request

Neil, have you got a couple of pointers for how you capture the array response and then use stringify too add to local storage? in bit of a newby with javascript so it's bit of a learning curve at the moment!

Katya, many thanks for your help. i think the link posted before is close to what I'm trying to do. all i need to figure out its how to capture the return array and loop through it in the javascript.

thanks both

Lewis

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Multiple Google Map Markers from REST request

Assuming your getting multiple results I would Store the entire response the parse it like so..
On the success event of your service add custom JS...
If u need it stored to display on other screen otherwise don't store and parse directly.
code localStorage.setItem('AllLocations', JSON.stringify(data.results));
Yours may be .. localStorage.setItem('AllJobs', JSON.stringify(data));
/code

On click event to show or any other event...
code
var dataall = JSON.parse(localStorage.getItem('AllLocations'));

for (var j=0; j<dataall&#46;length; j++) {
var thisLocation = dataall[j]&#46;latitude + ", " + dataall[j]&#46;longitude;
showSpots(thisLocation);&#47;&#47;Run map function to display results
}

function showSpots (thisLocation) {
&#47;&#47;Use thisLocation variable in the google maps "position:"
}
/code

This assumes your map is already initialized..
You can extract and pass on more data to your map as well...
Always check for 0 length b4 parsing And use Try catch blocks to prevent code errors on bad values or null etc.
Hope you get the idea.
Regards.

Willie Sims
Posts: 0
Joined: Wed Jul 10, 2013 4:37 pm

Multiple Google Map Markers from REST request

I know this Topic is old but for those who may be looking for a way to make this work from a database rest service
This works for me
Add Label Objects to the Map "Add Objects Here" White space., Make the Fonts as small as possible I have used as many as four labels
Add a List Database to the data section
Map the Array $ to the Top of the Marker Tree This creates the loop to list all the items in the database
Add the Lat and Lang to the Lat Lang in the Marker Section, Then map your label data for each field you wish to show, But only one Field to One Label each label will be one line in the info window, Map your Title to what ever you whish to be seen when the curser focuses on the marker
Delete the Address from the Address section and add a central location from most of your markers set zoom to get a good overview of your markers

Save and view, Again this works for me not sure if its the best way,

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Multiple Google Map Markers from REST request

Hi Willie,

Thank you for sharing this!

Erwin Oliva
Posts: 0
Joined: Wed Mar 12, 2014 6:36 am

Multiple Google Map Markers from REST request

Thank you Willie! Your tip saved me countless hours!

Return to “Issues”