Grab latitude/longitude and send to Google Maps API
Posted: Sun Jan 18, 2009 1:06 pm
I know when it comes to the Google Maps API that a lot of it has to do with JavaScript, but the part I need help with is the php portion of what I am trying to do. What I am trying to do is grab an address from my database, get the lagitude/longitude coordinates and plot them in a certain method. I can grab the address from my database, calculate the latitude/longitude coordinates, but I can't for the life of me figure out how to insert those latitude/longitude coordinates in the method where I need them.
Using static coordinates, everything works great. The thing is, I can't use static coordinates... Here is the code I am using (demo at http://gmaps-samples.googlecode.com/svn ... _lazy.html):
My problem is, instead of having static coordinates in
I want to use the dynamic coordinates calculated in
I have been searching and trying to figure this out for hours, but with no success. If anyone has any ideas on how I could use my dymically-generated coordinates instead of the static ones, I would greatly appreciate it. Thank you.
Using static coordinates, everything works great. The thing is, I can't use static coordinates... Here is the code I am using (demo at http://gmaps-samples.googlecode.com/svn ... _lazy.html):
Code: Select all
<?php require_once("connection.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>API</title>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&&v=2.x&key=[my api key would be here]"></script>
<script type="text/javascript">
<?php
//Code to collect information from database
$q_getaddress = "select * from sector WHERE id = " . $_GET['id'];
$r_getaddress = mysql_query($q_getaddress);
$dbaddress = mysql_fetch_object($r_getaddress);
?>
//<![CDATA[
var panorama;
var currentYaw = 180;
var currentPitch = 0;
var timer;
var currentZoom = 0;
var zoomingIn = true;
function getLocation() {
var address = "<?php echo $dbaddress->streetAddress?>";
var city = "<?php echo $dbaddress->city ?>";
var state = "<?php echo $dbaddress->state ?>";
var zip = "<?php echo $dbaddress->zip ?>";
// Retrieve location information, pass it to GetCoordinates()
geocoder.getLocations(address, GetCoordinates);
}
// This function adds the point to the map
function GetCoordinates(response)
{
// Retrieve the object
place = response.Placemark[0];
// Retrieve the latitude and longitude coordinates
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
}
function load() {
panorama = new GStreetviewPanorama(document.getElementById("pano"));
panorama.setLocationAndPOV(new GLatLng(45.595683, -122.503509), {yaw: currentYaw, pitch: currentPitch, zoom: currentZoom});
timer = window.setInterval(spiral, 200);
}
function spiral() {
currentYaw += 2;
panorama.panTo({yaw:currentYaw, pitch:currentPitch});
}
function stopAndZoom() {
clearInterval(timer);
zoomingIn = true;
timer = window.setInterval(zoom, 500);
}
function zoom() {
if (zoomingIn) {
currentZoom++;
} else {
currentZoom--;
}
panorama.panTo({yaw:currentYaw, pitch:currentPitch, zoom:currentZoom});
if (currentZoom == 2) {
zoomingIn = false;
}
if (currentZoom == 0) {
clearInterval(timer);
timer = window.setInterval(spiral, 200);
}
}
</script>
<body onload="load()" onunload="GUnload()">
<div id="pano" style='width:500px; height:400px'></div>
<br/>
<input type="button" onclick="stopAndZoom()" value="Click here to Stop and Zoom"/>
</body>
</html>
Code: Select all
panorama.setLocationAndPOV(new GLatLng(45.595683, -122.503509), {yaw: currentYaw, pitch: currentPitch, zoom: currentZoom});Code: Select all
// Retrieve the latitude and longitude coordinates
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);