I'm trying to make a Google map of the United States from data coming out of a Microsoft SQL Server.
I have this code but it displays nothing no error messages no map nothing:
PHP Code:
<!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>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=
ABQIAAAA5DlOXhx5QQLPMOOwqbU2RRbHPRyx4R338tPtgr_ht9D33FIxQ8Nv2ZPTWBF-B1MSToqBoZy2817Q"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var geocoder;
var map;
// On page load, call this function
function load()
{
var counter = 0;
// Create new map object
map = new GMap2(document.getElementById("map"));
// Create new geocoding object
geocoder = new GClientGeocoder();
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
$tsql = "Select Name, Phone, Address From Videographers";
$tsql2 = "SELECT COUNT(*) FROM videographers;";
include 'DBConnection.php';
$stmt = sqlsrv_query( $conn, $tsql);
$stmt2 = sqlsrv_query( $conn, $tsql2);
if( $stmt === false || $stmt2 === false) {
echo "Error in statement preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
$gettotal = sqlsrv_fetch( $stmt2 );
$total = sqlsrv_get_field( $stmt2, 0);
?>
// Map All Addresses
while (counter < <?php echo $total;?>) {
<?php
// Get All Videographers Data and Display it
// Retrieve location information, pass it to addToMap()
while ( sqlsrv_fetch( $stmt ) ){
$Name = sqlsrv_get_field( $stmt, 0);
$Phone = sqlsrv_get_field( $stmt, 1);
$Address = sqlsrv_get_field( $stmt, 2, SQLSRV_PHPTYPE_STRING( SQLSRV_ENC_CHAR));
?>
var address = "<?php echo $Address;?>";
geocoder.getLocations(address, addToMap);
<?php } ?>
counter = counter + 1;
}
}
// This function adds the point to the map
function addToMap(response)
{
// Retrieve the object
place = response.Placemark[0];
// Retrieve the latitude and longitude
point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
// Center the map on this point
map.setCenter(point,5);
// Create a marker
marker = new GMarker(point);
// Add the marker to map
map.addOverlay(marker);
// Add address information to marker
marker.openInfoWindowHtml(place.address);
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 400px; height: 300px"></div>
</body>
</html>
<?php
sqlsrv_free_stmt( $stmt);
sqlsrv_free_stmt( $stmt2);
sqlsrv_close( $conn);
?>
I think I'm missing something but not sure what. I also can't get javascript alerts to display for me so it may be a javascript problem.
This is what I get when I view the pages source.
Code:
<!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>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=
ABQIAAAA5DlOXhx5QQLPMOOwqbU2RRbHPRyx4R338tPtgr_ht9D33FIxQ8Nv2ZPTWBF-B1MSToqBoZy2817Q"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var geocoder;
var map;
// On page load, call this function
function load()
{
var counter = 0;
// Create new map object
map = new GMap2(document.getElementById("map"));
// Create new geocoding object
geocoder = new GClientGeocoder();
// Map All Videographers
while (counter < 5) {
var address = "123 main street Somerville,ma";
geocoder.getLocations(address, addToMap);
var address = "23 main street Somerville,ma";
geocoder.getLocations(address, addToMap);
var address = "123 college ave, somerville,ma";
geocoder.getLocations(address, addToMap);
var address = "12 holland street somerville,ma";
geocoder.getLocations(address, addToMap);
var address = "1 grove street somerville,ma";
geocoder.getLocations(address, addToMap);
counter = counter + 1;
}
}
// This function adds the point to the map
function addToMap(response)
{
// Retrieve the object
place = response.Placemark[0];
// Retrieve the latitude and longitude
point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
// Center the map on this point
map.setCenter(point,5);
// Create a marker
marker = new GMarker(point);
// Add the marker to map
map.addOverlay(marker);
// Add address information to marker
marker.openInfoWindowHtml(place.address);
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 400px; height: 300px"></div>
</body>
</html>
Any Ideas? Not sure if this should be in here javascript or databases as I don't know where the problem is either. Thanks for any ideas you can offer here. This is where I got the code for the google map I'm using:http://www.developer.com/lang/jscrip...le.php/3615681
Bookmarks