Skip to content Skip to sidebar Skip to footer

Unable To Return Latitude/longitude Result To Javascript Json From Php Mysql Query

I am trying to return database values for latitude and longitude from a PHP/MySQL query to my Javascript function in order to populate a google maps JSON request. My PHP/MySQL quer

Solution 1:

You are passing 'result' in as a string. You need to pass the result object, without the quotes:

var origin = google.maps.LatLng(result);

Keep in mind that $.getJSON is asynchronous. You probably need to wrap the rest of your gmaps code in a function declaration, and call that function in the $.getJSON callback after origin is set. Otherwise you're still trying to use origin before it has been fetched from the server.

Something like:

$.getJSON("phpsearch2.php", {name : startname}, function (result) {
    var origin = google.maps.LatLng(result);

    // Now that we have our origin, we can initialize the restinit(origin);
});

functioninit(origin) {
   var end = new google.maps.LatLng('37.738029', '-122.499481');
   var request = {
        origin: origin,
   <snip>
}

Post a Comment for "Unable To Return Latitude/longitude Result To Javascript Json From Php Mysql Query"