what i am trying to achieve is basically mark the location of all the users logged into my chat which is another thing. so i though i'd use geolocation api (http://code.google.com/apis/gears/api_geolocation.html) and store the generated location in a session variable. but its not working. here is the code-`
<?php
$my_lat= $_GET['test']; // get data
$my_long= $_GET['fname'];
$my_name = "vivek";
$lat1=28.635308;
$long1=77.22496;
//$latitude = $_GET['latitude'];
//$longitude = $_GET['longitude'];// get data
echo $my_lat.''.$my_long;
?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=''
&sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var longi= position.coords.longitude;
var url = 'bam.php';
//post to the server!
$.get(url, { test: lat,fname: longi },function(data){
alert('data was passed!');
});
}, function() {
//now is when the marking should be done.
handleNoGeolocation(true);
});
}
});
</script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(28.635308,77.22496);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var thelat = '<?php echo $my_lat;?>';
var thelong = '<?php echo $my_long;?>';
var seslatlng = new google.maps.LatLng(thelat,thelong);
alert(seslatlng);
var marker = new google.maps.Marker({
position: seslatlng,
map: map,
animation: google.maps.Animation.DROP,
title:"Hello world!",
});
}
</script>`
and the problem is. that the variable seslatlng is set to (0,0) always which is not what i want. i am new to PHP and i only have rough idea how server side scripting works. can somebody please fix this?
Instead of using and for assigning values to javascript variables, use:
var thelat = '<?=$my_lat?>';
var thelong = '<?=$my_long?>';
and it will work for you. I have also tried it to assign php variables value to javascript variables.
I don't see anywhere that you are setting seslatlng. If you're wanting this to be a JS variable, add:
var seslatlng = "(<?php echo $my_lat . ',' . $my_lng; ?>)"; // (30.230, 8.030)
when you are using jquery's ajax get function, what you wanna do is call a php function that only returns the locations. this is how is should look:
<?php
if ( $_GET['test'] ) {
$my_lat= $_GET['test']; // get data
$my_long= $_GET['fname'];
$my_name = "vivek";
$lat1=28.635308;
$long1=77.22496;
//$latitude = $_GET['latitude'];
//$longitude = $_GET['longitude'];// get data
echo $my_lat.''.$my_long;
} else {
?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=''
&sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var longi= position.coords.longitude;
var url = 'bam.php';
//post to the server!
$.get(url, { test: lat,fname: longi },function(data){
alert('My location is: ' + data);
});
}, function() {
//now is when the marking should be done.
handleNoGeolocation(true);
});
}
});
</script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(28.635308,77.22496);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var thelat = '<?php echo $my_lat;?>';
var thelong = '<?php echo $my_long;?>';
var seslatlng = new google.maps.LatLng(thelat,thelong);
alert(seslatlng);
var marker = new google.maps.Marker({
position: seslatlng,
map: map,
animation: google.maps.Animation.DROP,
title:"Hello world!"
});
}
</script>
<?php } ?>
The Best way is :
<script type="text/javascript">
var something=<?php echo json_encode($a); ?>;
</script>
Purpose of json_encode is to escpe the quotes and other entities <?php echo $a; ?> can break your code.
Related
I am using phonegap and I have a google map which locates the user and places a marker on the map. What I want to do is load markers from a mysql database which holds lat and long details for each place. Do I have to do this through php and ajax? This is the code I have at the moment. Thanks
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Test</title>
<link rel="stylesheet" href="/master.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':false,'timeout':10000});
}
//GEOLOCATION
var onSuccess = function(position) {
var myLat = position.coords.latitude;
var myLong = position.coords.longitude;
var myLatlng = new google.maps.LatLng(myLat, myLong);
//MAP
var mapOptions = {
center: new google.maps.LatLng(myLat, myLong),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body onload="onLoad()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
Define map
var map;
Initialize map:
function initialize(lat,lng, n) { //BY PASSING LATITUDE (lat), LONGITUDE (lng) AND THE TEXT (n) WILL SET A DEFAULT MARKER
var mapOptions = {
scaleControl: true,
center: new google.maps.LatLng(lat, lng),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var marker = new google.maps.Marker({
map: map,
position: map.getCenter()
});
var infowindow = new google.maps.InfoWindow();
infowindow.setContent('<b>ا'+n+'</b>');
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
call this function in device ready function.
You can pass current lat, long-
var myLat = position.coords.latitude;
var myLong = position.coords.longitude;
call a ajax request and get location data from server.
Insert all latitude and longitude in locations array within your ajax success request and call setMarkers method
var loc_array = new Array(); //LOCATION ARRAY
$.each(server_response_array, function(i,v){
loc_array[i] = [v.lat, v.lng, v.temp_txt];
}
setMarkers(loc_array);
function setMarkers(locations){
//clearMap();
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var marker, i
for (i = 0; i < locations.length; i++)
{
var loan = locations[i]['txt'];
var lat = locations[i]['lat'];
var lng = locations[i]['lng'];
latlngset = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
map: map, title: loan , position: latlngset, icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png' //THIS WILL SET A BLUE COLOR MARKER YOU CAN SET MORE COLOR AND ALSO CAN MANAGE FROM DATABASE
});
//map.setCenter(marker.getPosition())
var content = loan;
var infowindow = new google.maps.InfoWindow()
google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){
return function() {
infowindow.setContent(content);
infowindow.open(map,marker);
};
})(marker,content,infowindow));
}
}
Also see this link
goole-map-javascript-api-unable-to-load-markers-from-mysql-database
result of my post() only show data generated of other map.php but its unable to show map box. i am sending id through post() and it show the exact php data from mysql database. only map div is emptry. following is the code.
$(document).ready(function() {
$(".mylink").click(function(){
var $linkattr = $(this).attr("rel");
// alert($linkattr);
$.post("map.php", {myid:$linkattr}).done(function(data) {
$("#mapcomeshere").html(data);
evt.preventDefault();
});
});
});
my map.php script is
<?php
include('db.php');
$myid = "25";//$_POST['myid'];
$result = mysql_query("select * from property Where Id = '" . $myid ."' AND status = 1");
$row = mysql_fetch_array($result);
echo $row['Id'] . " : " . $row['owner'] . " : " . $row['lnglat'] . $row['propertyadd'] ."<br>";
$maploc = $row['lnglat'];
$myadd = $row['propertyadd'];
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: new google.maps.LatLng(24.893379,67.028061),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infoWindow = new google.maps.InfoWindow;
var onMarkerClick = function() {
var marker = this;
var latLng = marker.getPosition();
infoWindow.setContent('<?php echo $myadd ?>');
infoWindow.open(map, marker);
};
google.maps.event.addListener(map, 'click', function() {
infoWindow.close();
});
var marker1 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(<?php echo $maploc ?>)
});
google.maps.event.addListener(marker1, 'click', onMarkerClick);
});
</script>
hi
<div id="map"></div>
please help
There are a couple of things I can suggest.
Firstly, you have a conceptual problem in your code, where you write:
infoWindow.setContent('<?php echo $myadd ?>');
You need to understand that PHP is handled on the server, and as such, it cannot be directly executed by JavaScript in this way. What this will do, is literally change the content of the infoWindow to '<?php echo $myadd ?>'.
Now as for your question, I think you are going about it the wrong way by returning all that code over the AJAX response. The JavaScript should live in the page, and only the data should be returned by map.php, probably in the form of JSON data, for example:
map.php:
// ... database stuff, then finally:
echo json_encode(array(
'map' => array(
'lat' => 67.028061,
'long' => 24.893379,
'zoom' => 13
),
'infoWindowContent' => $myadd,
//... etc
));
The rest of that JavaScript belongs in the callback to $.post().
$.post("map.php", {myid:$linkattr}).done(function(data) {
// Not this: $("#mapcomeshere").html(data);
google.maps.event.addDomListener(window, 'load', function() {
var map = new google.maps.Map(document.getElementById('map'), data.map);
// ... setup event handlers, etc ...
});
});
What this does is provide a cleaner API for your code. The responsibility of map.php is only to provide the data for the map, not the JavaScript. The JavaScript is all in one place.
I have seen this link:
Google map api v3 add polylines from array
this is somehow slightly the same as my problem.. you see, im getting a javscript error as such this:
Uncaught TypeError: Cannot call method 'getPath' of undefined
AddCoordinate map:118
(anonymous function)
well my code is basically populating the coordinates first as the page is loaded together with the map.. And by the time that click is triggered (html button), that is the only time that the map will be plotted with poly lines.. I hope I explained it very well though.. Here's what i got:
var map;
var Markers = [];
var Coordinates = [];
var LinePath;
function initialize()
{
var myLatLng = new google.maps.LatLng(21.291982, -140.821856);
var myOptions = {
zoom: 3,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var MarkerSize = new google.maps.Size(48,48);
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function AddCoordinate( lat, long ) {
var path = LinePath.getPath();
path.push( new google.maps.LatLng( lat, long ) );
LinePath.setPath(path);
}
function PlotLine()
{
LinePath = new google.maps.Polyline({
path:Coordinates,
strokeColor:"#ffffff",
strokeOpacity:1.0,
strokeWeight:5
});
LinePath.setMap(map);
}
<html>
<body onload="initialize()">
<div id="map_canvas" ></div>
<?php
foreach($arrayOfPlotPoints as $key => $value){
$longitude = round($value['longitude'],5);
$latitude = round($value['latitude'],5);
$snrLevel = $value['snr_level'];
echo '<script type="text/javascript">AddCoordinate('.$latitude.','.$longitude.')</script>';
?>
<option value="<?php echo $longitude.",".$latitude.",".$snrLevel?>"> Lg:<?php echo $longitude." Lt: ".$latitude." LV: ".$snrLevel?></option>
<?php } ?>
</select>
<br /><br />
<?php echo $this->Form->button('PLOT', array('type'=>'button', 'onclick'=>'PlotLine()')); ?>
echo $this->Form->button('PLOT', array('type'=>'button', 'onclick'=>'PlotLine()'));
?>
********EDITED**********
i have made a partial modification of my code.. however im getting the same error..
Uncaught TypeError: Cannot call method 'getPath' of undefined
AddCoordinate (anonymous function)
function initialize() {
//.....
LinePath = new google.maps.Polyline({
path:Coordinates, //san ka galing Coordinates??? dineclare ka pero di ka aman nilagyan "YATA" ng laman
strokeColor:"#ffffff",
strokeOpacity:1.0,
strokeWeight:5
});
}
function AddCoordinate( latitude, longitude ) {
var path = LinePath.getPath();
path.push( latitude, longitude );
}
function PlotLine()
{
LinePath = new google.maps.Polyline({
path:Coordinates,
strokeColor:"#ffffff",
strokeOpacity:1.0,
strokeWeight:5
});
LinePath.setMap(map);
}
<HTML>
select name="long_and_lat" id="long_and_lat" style="width:220px;height:250px;" size="100">
<?php
$plotPoints = array();
foreach($arrayOfPlotPoints as $key => $value){
$longitude = round($value['longitude'],5);
$latitude = round($value['latitude'],5);
$snrLevel = $value['snr_level'];
echo '<script type="text/javascript">AddCoordinate('.$latitude.','.$longitude.')</script>';
?>
<option value="<?php echo $longitude.",".$latitude.",".$snrLevel?>"> Lg:<?php echo $longitude." Lt: ".$latitude." LV: ".$snrLevel?></option>
<?php } ?>
</select>
<br /><br />
<?php echo $this->Form->button('PLOT', array('type'=>'button', 'onclick'=>'PlotLine()')); ?>
</html>
You are making a call to LinePath in AddCoordinate(), but LinePath isn't created until PlotLine() is called (by clicking the button).
Perhaps you could create LinePath when you declare it, then just call LinePath.setMap(map); from PlotLine().
Maybe something like this:
<html>
<head>
<link href="https://google-developers.appspot.com/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var Markers = [];
var Coordinates = [];
var LinePath = new google.maps.Polyline({
path:Coordinates,
strokeColor:"#ffffff",
strokeOpacity:1.0,
strokeWeight:5
});
function initialize()
{
var myLatLng = new google.maps.LatLng(21.291982, -140.821856);
var myOptions = {
zoom: 3,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var MarkerSize = new google.maps.Size(48,48);
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function AddCoordinate( lat, long ) {
var path = LinePath.getPath();
path.push( new google.maps.LatLng( lat, long ) );
LinePath.setPath(path);
}
function PlotLine()
{
LinePath.setMap(map);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" ></div>
<script type="text/javascript">AddCoordinate(11,12)</script>
</body>
</html>
When You click on anywhere in map 1 new marker created and make polygon
its working fine but now my problem is i can't get is my marker which is coming from database is inside polygon or not, how to know it???
<?php include("config.php"); ?>
<?php $result = mysql_query("select * from `googlemaps`"); ?>
<html>
<head>
<title>Google Maps</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var poly, map;
var markers = [];
var path = new google.maps.MVCArray;
function initialize() {
var LatLng = new google.maps.LatLng(23.183, 75.767);
map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: LatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
function createMarker(point, title) {
var infowindow = new google.maps.InfoWindow({
content: "<span style='color:blue;'>"+title+"</span>"
});
var marker = new google.maps.Marker({
position: point,
map: map,
title:title
});
marker.Image ='https://d3szoh0f46td6t.cloudfront.net/public/1626980/small';
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map,marker);
});
return marker;
}
<?php
if(mysql_num_rows($result)>0)
{
while( $data = mysql_fetch_array($result) )
{ ?>
createMarker(new google.maps.LatLng(<?php echo $data['lat']; ?>, <?php echo $data['lon']; ?>), "<?php echo $data['title']; ?>");
<?php }
}
?>
poly = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
poly.setMap(map);
poly.setPaths(new google.maps.MVCArray([path]));
google.maps.event.addListener(map, 'click', addPoint);
}
function addPoint(event) {
path.insertAt(path.length, event.latLng);
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
marker.setTitle("#" + path.length);
google.maps.event.addListener(marker, 'click', function() {
marker.setMap(null);
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
markers.splice(i, 1);
path.removeAt(i);
}
);
google.maps.event.addListener(marker, 'dragend', function() {
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
path.setAt(i, marker.getPosition());
document.getElementById("abc").innerHTML=path.setAt(i, marker.getPosition());
}
);
}
</script>
</head>
<body style="margin:0px; padding:0px;" onLoad="initialize()">
<div id="map" style="width:500px; height:500px;"></div>
<div id="abc"></div>
</body>
</html>
You might be asking how to check this javascript or php. I am not aware of a GIS framework in these areas.
Most of the spatial databases (like SQL Server/Postgresql which I have worked with) provide features like ST_Contains or ST_Distance which you can make use of. I think this is part of OpenGIS specification.
I think you might probably be using MYSQL. So may just need to search for a function.
I have this simple hello world version of a google map api javascript v3 and it works for a static geocode. My data is normal addresses (i.e. "30 rockefeller center, New York, NY").
This data is being called from with php from a mysql database. I can get the address on the page with something like this...For the purpose of this post, say this would have all info: address, city, state, zip code
<?php echo $row_query_details['address'];?>
So, I need to geocode this info for the map. I'm very comfortable with mysql and php, but not as much with javascript. I have been trial/error and researching this for a couple of days.
I have looked everywhere for a working sample or example and feel like this relatively simple problem must have been asked and answered many times over, but I cannot figure it out!
Thanks in advance.
Here is the code I'm working with:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: latlng,
title:"Hello World!"
});
// To add the marker to the map, call setMap();
marker.setMap(map);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:500px; height:500px"></div>
</body>
</html>
Hello and happy anniversary (regarding your question and tutorial).
I am a web-developer and must thank you. I used this tutorial as I currently do not have a way to geocode via submit (lat/long needs to be pulled from address stored in db) as I am consulting an existing site and have minimal access to backend code.
To answer your question regarding marker interactivity, this takes a few easy steps:
1) Provide some content. This is done before declaring the geocoder (var geocoder;):
var contentString =
'line 1'+
'line 2';
2) Underneath the marker declaration ( var marker = new google.maps.Marker({ ), you will need to declare infowindow and add the event listener:
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
Edit:
I have successfully pulled array information from a MySQL database by expanding on your method. My method is here:
1) Basic php below:
include (dbinfo.php)
$result = mysql_query( 'SELECT * FROM table')
$count = 0
2) Setting up google maps API:
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=yourkey&sensor=false">
</script>
3) Geocoding setup below:
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
var latlng = new google.maps.LatLng(yourlat, yourlong); //This is to center the map
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
<?php //Starts while loop so all addresses for the given information will be populated.
while($row = mysql_fetch_array($result)) //instantiates array
{ ?>
geocoder = new google.maps.Geocoder();
var address = '<?php echo $row['address'].', '.$row['city'].', '.$row['state'].', '.$row['zip'].', '.$row['country']; ?>';
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//marker generation is done though adding the primary ID to the "marker" variable, so if address "1" has the primary ID of "1", your marker would read "marker1"
var marker<?php print $row['primaryID']; ?> = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: "This can be a php variable or whatever you like. It is displayed on hover."
});
//var contentString manages what is seen inside of the popup
var contentString =
'line 1'+
'line 2';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker<?php print $row['primaryID']; ?>, 'click', function() {
infowindow.open(map,marker<?php print $row['primaryID']; ?>);
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
<?php
$count++;
} //ends while
?>
}
/*end javascript*/
</script>
Thank you very much again for posting this. It was very useful.
You can use your PHP variable into JavaScript by passing php variables in function initialize().
your body tag will look like below;
For Ex:
<body onload="initialize('<?php echo $row_query_details['address'];?>')">
Then you will use this particular variable in your javascript code, your javascript function will look like below:
<script type="text/javascript">
function initialize(address) {
var G_address = address;
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: latlng,
title:"Hello World!"
});
// To add the marker to the map, call setMap();
marker.setMap(map);
}
</script>
Now you can use this G_address JavaScript variable dynamically in your G-MAP code..
This will be helpful to you..
So, I'm going to answer my own question here. The first answer provided I was not able to utlize. I'm not sure if the answer was incomplete or I just didnt' follow it. Regardless, here's what the code looks like:
First I had my address components pulling from the mysql db and I assigned them variables, like this:
$county = $row_qry['county'];
$address = $row_qry['address'];
$city = $row_qry['city'];
$state = $row_qry['state'];
Then, my google v3 stuff looks like this:
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(34.052234,-118.243685);
var address = '<?php echo $address.', '.$city.', '.$state; ?>';
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
And that sort of answers my question. There are a couple of issues I still need to resolve, such as (a) how to make the marker be clickable and interactive, and (b) the map flashes a the geocode first defined (34.05,-118.24) before showing the correct address.
Both of these issues I need to still resolve, but at least the geocoding is working successfully. Hope this helps someone else.
Thanks!