Last active
December 22, 2015 16:38
-
-
Save dcblogdev/6500340 to your computer and use it in GitHub Desktop.
Google Maps Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "<div id=\"pmap\"></div>\n"; | |
echo '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script type="text/javascript" src="'.DIR.'assets/templates/js/jquery-1.6.4.min.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
$(document).ready(function(){ | |
function initialize() { | |
var geocoder; | |
var map; | |
var address = \''.$r->postTitle.' '.$r->postCode.' Hull\'; | |
geocoder = new google.maps.Geocoder(); | |
var latlng = new google.maps.LatLng(-34.397, 150.644); | |
var myOptions = { | |
zoom: 15, | |
center: latlng, | |
mapTypeId: google.maps.MapTypeId.SATELLITE | |
} | |
map = new google.maps.Map(document.getElementById("pmap"), myOptions); | |
var contentString = \'<div id="infoContent">\'+ | |
\'<div id="infoBody">\'+ | |
\'<p>'.$r->postTitle.' <br /> '.$cr->catTitle.'</p>\'+ | |
\'<p><a href="http://maps.google.com/maps?saddr=&daddr='.$r->postTitle.' '.$cr->catTitle.'" target ="_blank">Get Directions</a></p>\'+ | |
\'</div>\'+ | |
\'</div>\'; | |
if (geocoder) { | |
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, | |
title: \'\' | |
}); | |
var infowindow = new google.maps.InfoWindow({ | |
content: contentString, | |
maxWidth: 700 | |
}); | |
google.maps.event.addListener(marker, \'click\', function() { | |
infowindow.open(map,marker); | |
}); | |
} else { | |
alert("Geocode was not successful for the following reason: " + status); | |
}}); | |
} | |
}//close initialize | |
initialize(); | |
}); | |
</script>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment