• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 471
  • Last Modified:

Dynamic Google Map JSON or XML and AJAX

Hi -

I'm not much of a front end/javascript type person - so forgive me if my question seems a little obvious.

I've got a google map (api v3).  I want to be able to send search queries to some backend scripts that I've generated that will output the name, latitude and longitude of various things depending on the search criteria.  I'd then like that output to be updated to the google map on screen without having to reload the page.

I've written the backend SQL scripts and PHP - for both JSON and XML - and they work perfectly.  It's populating the front end that I'm having difficulty with - and I can't find any decent documentation on how to properly do it.

Is it an AJAX routine that I'm looking for - and what's your best suggestion on how to get it done?

The routine needs to:
send the query to the script (GET, variables)
grab the response (either in XML or JSON)
Clear the map of previous search markers
Populate with new search marker results

1 Solution
Evan CutlerVolunteer Chief Information OfficerCommented:
function getLocations() {      $.getJSON("<INSERT PHP/JSON OUTPUT HERE>", function (json) {          var location;           $.each(json.zones, function (i, item) {             addMarker(item.Latitude,item.Longitude);         });      }); }  function addMarker(lat,lng) {         marker = new google.maps.Marker({             position: new google.maps.LatLng(lat,lng),             map: map,             icon: redImage         });         markersArray.push(marker); }

This might work for you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now