Google Map

<?php
$link = mysql_connect(‘localhost’, ‘root’, ”)  or die(mysql_error());
$db = mysql_select_db(‘map’,$link) or die(mysql_error());
$select = “select * from markers”;
$query = mysql_query($select) or die(mysql_error());
$locations = array();
while($row=mysql_fetch_object($query))
{
$locations[] = “[‘”.$row->address.”‘, “.$row->lat.”, “.$row->lng.”, ‘”.$row->image.”‘]”;
}
$loc =implode(‘,’,$locations);
?>
<script src=”https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false”></script&gt;
<script type=”text/javascript”>
var markers = [];
function initialize() {

var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(28.578579, 77.317268),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById(“googlemap”), mapOptions);

var locations = [<?php echo $loc;?>];

var marker, i;
var infowindow = new google.maps.InfoWindow();

google.maps.event.addListener(map, ‘click’, function() {
infowindow.close();
});

for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: locations[i][3]
});

google.maps.event.addListener(marker, ‘click’, (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));

markers.push(marker);
}

}
google.maps.event.addDomListener(window, ‘load’, initialize);

function myClick(id){
google.maps.event.trigger(markers[id], ‘click’);
}
</script>
<div id=”googlemap” style=”width: 100%; height: 500px;”></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