Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 667307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:54:49+00:00 2026-05-13T23:54:49+00:00

I am new to the googlemaps API. I have written a small app for

  • 0

I am new to the googlemaps API. I have written a small app for my mobile phone that periodically updates its location to an SQL databse.

I would like to display this information on a googlemap in my browser. Ideally i’d like to then poll the database periodically and if any new co-ords have arrived, add them to the line.

Best way of describing it is this.

In a quest to get to there, i’ve started on the documents on google and been modifying them to try and acheive what I want. It doesn’t work – and i don’t know enough to know why. I would love some advice as to why, and any pointers towards my ultimate goal would be very much welcomed.

Google Maps AJAX + MySQL/PHP Example

   <script type="text/javascript">
  //<![CDATA[

function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(47.614495, -122.341861), 13);

    GDownloadUrl("phpsqlajax_genxml.php", function(data) {
      var xml = GXml.parse(data);
      var line = [];
      var markers = xml.documentElement.getElementsByTagName("points");
        for (var i = 0; i < points.length; i++) {
            var point = points.item(i);
            var lat  = point.getAttribute("lat");
            var lng  = point.getAttribute("lng");

            var latlng = new GLatLng(lat, lng);

       line.push(latlng);
       if (point.firstChild) {
         var station = point.firstChild.nodeValue;
         var marker = createMarker(latlng, station);
         map.addOverlay(marker);
       }
     }

     var polyline = new GPolyline(line, "#ff0000", 3, 1);
     map.addOverlay(polyline);
});
}
//]]>

My php file is generating the following XML;

<?xml version="1.0" encoding="UTF-8" ?>
<points>
<point lng="-122.340141" lat="47.608940"/>
<point lng="-122.344391" lat="47.613590"/>
<point lng="-122.356445" lat="47.624561"/>
<point lng="-122.337654" lat="47.606365"/>
<point lng="-122.345673" lat="47.612823"/>
<point lng="-122.340363" lat="47.605961"/>
<point lng="-122.345467" lat="47.613976"/>
<point lng="-122.326584" lat="47.617214"/>
<point lng="-122.342834" lat="47.610126"/>
</points>

I have successfully worked through this; http://code.google.com/apis/maps/articles/phpsqlajax.html before attempting to customise the code.

Any pointers? Where am I go wrong?

  • 1 1 Answer
  • 5 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:54:50+00:00Added an answer on May 13, 2026 at 11:54 pm

    You seem to be on the right track.

    Your php script should accept a timestamp parameter, and should check if new points have been inserted in the database after that timestamp. If yes, it should return a response with the latest entry (or a list of entries after that timestamp, if you want to show a live trail as the vehicle moves).

    On the client-side, you may want to initiate an AJAX request to the server-side script, either using normal or long polling, with the timestamp parameter of the last update.

    When your AJAX request receives new information from the server, you would simply move your markers on the map. Then initiate a new AJAX request with the updated timestamp paramater.

    Pseudocode-ish example using jQuery:

    var lastUpdate = '2000/01/01 00:00:00';
    
    function autoUpdate () {
        $.ajax({
           type: "GET",
           url: "phpsqlajax_genxml.php?last_update=" + lastUpdate,
           dataType: 'xml',
           success: function(xmlData) {
    
              // 1. Check if the xmlData is empty. If not we received 
              //    some fresh data.
              // 2. Update lastUpdate from the xmlData with the timestamp from 
              //    the server. Don't use JavaScript to update the timestamp, 
              //    because the time on the client and on the server will 
              //    never be exactly in sync.
              // 3. Move the markers on Google Map.
    
              // Relaunch the autoUpdate() function in 5 seconds.
              setTimeout(autoUpdate, 5000);
           }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to both javascript and the googlemaps api but have had some
I'm new to Android development and have some question regarding overlays in googlemaps API.
I'm new to Android development and have some question regarding overlays in googlemaps API.
I have a web app that uses Google Maps API v3. I have it
I'm quite new to Javascript and the GoogleMaps API.. I have a problem with
I'm working on an application that uses the Google Maps API. I have no
I'm using the Google Maps Javascript API and I have LatLng coordinates that are
I have a written a simple code which would display the location on the
I'm new to the Google Maps API and have just taken over an RoR
I have the following Javascript that includes both the standard Google Maps API initialize()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.