
April 9th, 2010, 04:27 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 5
Time spent in forums: 1 h 10 m 46 sec
Reputation Power: 0
|
|
Problems with Google Geocoder in javascript
Can someone explain why this codes doesn't run? I have manged to get locations out of a SQL database using php and then transfering it to a javascript array but I want to send this information into a google geocoder to post it to a map. I seem to be having conceptual issues with google geocoder, ive read the API by im ability to understand everything so far is apparently too limited and I can't get access to the google forums, I think it has to do with me being in China.
Code:
for (i = 0; i <= iplist.length-1; i++){ geocoder.getLocations(address, addToMap); }
Code:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var iplist = new Array();
var address = "China";
/*
mysql_connect('gierkep.ipagemysql.com', 'trackmaster', 'xia8xiao');
mysql_select_db('ipaddresses_1');
$link = mysql_connect('gierkep.ipagemysql.com', 'trackmaster', 'xia8xiao');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('ipaddresses_1');
$countrytest = 'SELECT * FROM `iplocations`';
$countryquery = $countrytest;
$moreresults = mysql_query($countryquery) or die(mysql_error());
$x = 5;
while($row = mysql_fetch_array($moreresults))
{
$countryinstance = $row['country'];
echo "\n" . "iplist.push(" . json_encode($countryinstance) . ");" . "\n";
}
?>*/
<?php
$listofips = array(
array((string)("0"), (string)("0"), (string)("Number 1")),
array((string)("50"), (string)("50"), (string)("Number 2")),
array((string)("50"), (string)("-50"), (string)("Number 3")),
array((string)("-50"), (string)("50"), (string)("Number 4")),
array((string)("-50"), (string)("-50"), (string)("Number 5")),
array((string)("50"), (string)("100"), (string)("Number 6")),
array((string)("-50"), (string)("100"), (string)("Number 7")),
array((string)("50"), (string)("-100"), (string)("Number 8")),
array((string)("-50"), (string)("-100"), (string)("Number 9"))
);
$entrycount = count($listofips);
for ($x = 0; $x <= $entrycount -1; $x += 1)
{
echo "\n" . "var ip = new Array(" . $listofips[$x][0] . ", " . $listofips[$x][1] . ", " . json_encode($listofips[$x][2]) . ");" . "\n";
echo "iplist.push(ip);" . "\n";
}
?>
function initialize()
{
var latlng = new google.maps.LatLng(0,0);
var myOptions =
{
zoom: 1,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
alert('geocoder function about to call');
alert(window.location.host);
//Print all the markers here
for (i = 0; i <= iplist.length-1; i++)
{
var yourlat = parseInt(iplist[i][0]);
var yourlng = parseInt(iplist[i][1]);
var text = iplist[i][2];
text.toString();
var point = new google.maps.LatLng(yourlat,yourlng);
var marker = new google.maps.Marker
({
position: point,
map: map,
title: text
});
}
//for (i = 0; i <= iplist.length-1; i++){ geocoder.getLocations(address, addToMap); }
}
function addToMap(response)
{
alert('geocoder function called');
var text = "Rollover Text Under Development";
text.toString();
var point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
var marker = new google.maps.Marker({
position: point,
map: map,
title: text
});
}
</script>
</head>
<body onLoad="initialize()">
<div id="map_canvas" style="width:550; height:400"></div>
</body>
</html>
|