How show google map using PHP and javascript

Posted: January 8, 2013 in Uncategorized

<?php

$Query = “select * from `”.SITE_TABLE_PREFIX.”site_settings` “;
$objDB->setQuery($Query);
$rs = $objDB->select();

$address = ”.ucwords($rs[0][‘map_location’]).”;
$city = ”.ucwords($rs[0][‘city’]).”;
$state = ”.ucwords($rs[0][‘state’]).”;
$zip = ”.$rs[0][‘zip’].”;

$address_string = $address.’ ‘.$city.’, ‘.$state.’ ‘.$zip.’, ‘.ucwords($rs[0][‘country’]).”;

?>

Use the following javascript:

<script type=”text/javascript”>
var geocoder;

var map;

function initialize() {

geocoder = new google.maps.Geocoder();

var latlng = new google.maps.LatLng(”,”);

var myOptions = {

zoom: 8,

center: latlng,

mapTypeId: google.maps.MapTypeId.ROADMAP

}

map = new google.maps.Map(document.getElementById(“map_canvas”), myOptions);

}

 

function codeAddress(v) {

var address = v;
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>

Also use the following

<body onload=”initialize(); codeAddress(‘<?=stripslashes($address_string);?>’); codeAddress(‘<?=stripslashes($address_string2);?>’); “>

<div id=”map_canvas” style=”width:270px; height:200px;”></div>

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s