Dynamic Google Map JSON or XML and AJAX

Posted on 2011-10-11
Last Modified: 2012-05-12
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

Question by:erzoolander
    1 Comment
    LVL 9

    Accepted Solution

    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.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now