Problems with combining js,php and googlemaps

daveco

New Member
To better explain my problem i think that in my case the code will speak more than a thousand words.Just a brief intro though, my problem is that i can't retrieve a json encoded array with some coordinates inside and give it to the google map .js responsible for showing them on a map Here is my code in several files.1) jscookies.js (just a file including the cookies we all can use in javascript)2) process.php (in here i produce an array with coordinates, encode it and pass it through a echoed script to the third file, map.html, using cookies)\[code\]<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel="stylesheet" type="text/css" href="http://stackoverflow.com/questions/9600902/css/content.css" /> <script type="text/JavaScript" src="http://stackoverflow.com/questions/9600902/js/gmapinit.js"></script> <script type="text/JavaScript" src="http://stackoverflow.com/questions/9600902/js/jscookies.js"></script> </head><body> <?php ... ... $coordinatesarray = ...; echo "<script type=\"text/javascript\"> var my_cord_array =" . json_encode($coordinatesarray) . "; setCookie(\"mycookie\", my_cord_array, 1); </script>"; echo "<input type=\"button\" value=http://stackoverflow.com/"Next" onClick=\"location.href='http://stackoverflow.com/questions/9600902/map.html'\">"; ?></body></html>\[/code\]3) map.html (in this file I retrieve the array from the cookie and use it as the parameter for my gmapinit function in gmapinit.js)\[code\]<!DOCTYPE html><html><head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <link rel=stylesheet type="text/css" href="http://stackoverflow.com/questions/9600902/css/googlemap.css" /> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCbNM4y2fJ4AdCoXcWW-sGXPl5nXaJogPA&sensor=false"> </script> <script type="text/JavaScript" src="http://stackoverflow.com/questions/9600902/js/gmapinit.js"></script> <script type="text/JavaScript" src="http://stackoverflow.com/questions/9600902/js/jscookies.js"></script> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> var my_cord_array = getCookie("mycookie"); </script></head><body onLoad="init_map_and_markers(my_cord_array)"> <div id="map_canvas"> </div> </body>\[/code\]4) gmapinit.js (the gmapinit function responsible of all the drawings on the google map)\[code\]function init_map_and_markers(my_cord_array) { var global_markers = []; //test (the parameter is successfully PASSED!)/*for(var count = my_cord_array.length - 1; count >= 0; --count) { var o = my_cord_array[count]; var usr = o.user; var lati = o.lat; var lngi = o.lng; alert(usr + " " + lati + " " + lngi);}*///test (the parameter is successfully PASSED!) var infowindow = new google.maps.InfoWindow({}); var latlng = new google.maps.LatLng(27.059126, -41.044922); var myOptions = { zoom: 3, center: latlng, mapTypeId: google.maps.MapTypeId.HYBRID }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); for (var i = 0; i < markers.length; i++) { for(var count = my_cord_array.length - 1; count >= 0; --count) { var o = my_cord_array[count]; var lat = parseFloat(o.lat); var lng = parseFloat(o.lng); var markerdata = http://stackoverflow.com/questions/9600902/o.user; var myLatlng = new google.maps.LatLng(lat, lng); var contentString ="<html><body><div><p><h2>" + markerdata + "</h2></p></div></body></html>"; var marker = new google.maps.Marker({ position: myLatlng, map: map, title: "Coordinates: " + lat + " , " + lng + " | Marker Data: " + markerdata }); marker['infowindow'] = contentString; global_markers = marker; google.maps.event.addListener(global_markers, 'click', function() { infowindow.setContent(this['infowindow']); infowindow.open(map, this); }); } }}\[/code\]the result is that doing some tests and changing the code either the map doesn't show but the data about the coordinates are shown in the alert commands or the map shows but no marker are created with the coordinates given by the parameter arrayProbably the mistake is really stupid but as i am experiencing the combination of js php and html only by a few months now i believe i am missing something here.Any ideas?
 
Back
Top