Json object to populate google maps
Im trying to get the data from my msql databse into a html document and
thenvturn it into a json object so later on i can call it to use in google
maps. I have no idea whats wrong with this json string though any ideas?.
And it woiuld be helpful if any of you had any idea how i would call it to
get the tables i wanted into the google maps api.
Here is my json object that kinda works.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="generator" content="CoffeeCup HTML Editor
(www.coffeecup.com)">
<meta name="dcterms.created" content="Sun, 25 Aug 2013
10:26:05 GMT">
<meta name="description" content="">
<meta name="keywords" content="">
<title></title>
</head>
<?php
$db =
mysql_connect("careemprod.cmsz241itecr.eu-west-1.rds.amazonaws.com","careem-3","l1mit3dAcc0untCr3dent1@ls");
mysql_select_db("careem", $db);
date_default_timezone_set("Asia/Dubai");
$query = mysql_query("select
booking.id,booking.pick_up_location_id,booking.drop_off_location_id,booking_time,location.latitude,location.longitude,location_type,count(booking.id)
from booking
left join trip on booking.id = trip.booking_id
left join location on booking.pick_up_location_id = location.id
where location.latitude != 0 and location.longitude != 0 and
location_type != 98 and location_type != 0
group by pick_up_location_id
order by count(booking.id) desc");
$rows = array();
while($result = mysql_fetch_assoc($query)) {
$row["booking.id"] = $result["booking_ID"];
$row["booking.pick_up_location_id"] =
$result["pick_up_location_id"];
$row["booking.drop_off_location_id"] =
$result["drop_off_location_id"];
$row["booking_time"] = $result["booking_time"];
$row["location.latitude"] = $result["lat"];
$row["location.longitude"] = $result["lng"];
$row["location_type"] = $result["location_type"];
$row["count(booking.id)"] = $result["booking_multiplyer"];}
{
header('Content-type: application/json');
print json_encode(array(''=>$result));
}
?>
<body>
</body>
</html>
Here is an idea how i would use the object.
PageLoad(s,e)
{
var jsonString =
document.getElementById("hidMarkers").value;//which includes
lat and long values as json object.
var markersJson = jQuery.parseJSON(jsonString);
for (var i = 0; i < markersJson.length; i++) {
var latLng = new
google.maps.LatLng(markersJson[i].lat,
markersJson[i].lng);
var marker = new google.maps.Marker({ position:
latLng, clickable: true, icon:
markersJson[i].iconPath, map:map });
}
}
No comments:
Post a Comment