Jump to content

AJAX, JSON & Google Maps question.


sepoto
 Share

Recommended Posts

 // // // // // // // // Ajax returns from PHPxmlhttp.onreadystatechange=function() {if (xmlhttp.readyState==4 && xmlhttp.status==200){var obj = $.parseJSON(xmlhttp.responseText); var tLat = getCookie("tLat");var tLng = getCookie("tLng"); var options = { zoom: 4, center: new google.maps.LatLng(40.7257, -74.0047), mapTypeId: google.maps.MapTypeId.ROADMAP}; // Creating the map  var map = new google.maps.Map(document.getElementById('map'), options); alert(obj[0][1]+','+obj[0][2]); //var myLatLng = new google.maps.LatLng(40.7257, -74.0047);var myLatLng = new google.maps.LatLng(String(obj[0][1]), String(obj[0][2])); var marker = new google.maps.Marker({ position: myLatLng, map: map }); $('#map').show();}}// // // // // // // //

My alert is showing "-84.3132324,34.0393598". Uncommenting "//var myLatLng = new google.maps.LatLng(40.7257, -74.0047);" shows the marker beautifully. The current "var myLatLng = new google.maps.LatLng(String(obj[0][1]), String(obj[0][2]));" will not show me the marker. I for the life of me can not figure out why yet. ????????????????????????????????? Thanks a bunch!

Link to comment
Share on other sites

what he is saying is you are casting them to strings, by using the String Constructor

String(obj[0][1]), String(obj[0][2])

so try not doing that

new google.maps.LatLng(obj[0][1], obj[0][2]);

Link to comment
Share on other sites

This: var myLatLng = new google.maps.LatLng(obj[0][1], obj[0][2]); For some reason does not show the marker either. Those values started as floating point values in my MySQL database. They get retrieved and converted to a JSON array which is decoded into the array obj. What happens from there I don't know all the details yet. I just know that the constructor is not accepting them.

Link to comment
Share on other sites

I put your line in (with a minor edit ;) ). The code runs with no errors in the console however there is no marker yet. This is a very vexing problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...