I am missing a lot of the information required to do that as I am
completely new to Google Maps APIs. At the moment I am attempting to
just mark one location from a MySQL database just to do it all in baby
steps. I figure this is the first one I need to overcome. The URL of
the page I am attempting this on is:
http://www.caffeineauthority.com.au/app/map_search.php
The source is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="
http://maps.google.com/maps/api/js?
sensor=false"></script>
<link rel="stylesheet" type="text/css" href="../css/map_search.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check Location</title>
<? require('../php_incl/db_user_connect.php');
$query = ("SELECT * FROM cafe_info WHERE tl_id=1");
$go = mysql_query($query) or die(mysql_error());
$array = mysql_fetch_array($go);
if (!$array['address2']){
$address = $array['address1']." ".$array['suburb']." ".
$array['state']." ".$array['postcode'];
} else {
$address = $array['address1']." ".$array['address2']." ".
$array['suburb']." ".$array['state']." ".$array['postcode'];
}
$address = urlencode($address);
?>
<script type="text/javascript" src="
http://maps.google.com/maps/api/
geocode/json?address=<? echo $address; ?>&sensor=false"></script>
<script type="text/javascript" src="../js/map_search.js">
</script>
</head>
<body onload="initialize()">
<h1>Check your address</h1>
<h2>Instructions:</h2>
<ol><li>Check to see if[marker_img] corresponds with the location of
your cafe.</li>
<li>If [marker_img] does not line up with the street location of your
cafe, use your mouse to move it into the right location.</li>
<li>Once [marker_img] is in the right position click [save] to
continue.</li></ol>
<p><? print $address; ?></p>
<div id="map_canvas"></div>
</body>
</html>
map_search.js:
var myLat = myJSONResult.results[0].geometry.location.lat;
var myLng = myJSONResult.results[0].geometry.location.lng;
function initialize(){
var myLatlng = new google.maps.LatLng(myLat,myLng);
var myOptions = {
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
}
I cannot work out why it won't plot my marker on the location I have
searched. I have tested the search function, and it does give me a
result. But for some reason I am let down by:
var myLat = myJSONResult.results[0].geometry.location.lat;
var myLng = myJSONResult.results[0].geometry.location.lng;
For some reason this returns no results.
Am I placing that piece of code in the wrong location?
Regards.
On Mar 16, 6:49 pm, "
geocode...@gmail.com" <
geocode...@gmail.com>