Skip to content

Instantly share code, notes, and snippets.

@luanmuniz
Created December 31, 2014 04:41
Show Gist options
  • Save luanmuniz/956b30c30d605ff5109e to your computer and use it in GitHub Desktop.
Save luanmuniz/956b30c30d605ff5109e to your computer and use it in GitHub Desktop.
GoogleMaps Easyway
<script src='http://maps.google.com/maps/api/js?sensor=false' type='text/javascript'>
</script>
<script type='text/javascript'>
$(document).ready(function() {
$('#map-container').googleMap("3333 RiverBend Drive, Springfield, OR");
});
</script>
$.fn.googleMap = function(address, options) {
var defaults = {
lat: 44.081996,
long: -123.0286928,
zoom: 14,
mapTypeId: google.maps.MapTypeId.HYBRID
};
options = $.extend(defaults, options || {});
var center = new google.maps.LatLng(options.lat, options.long);
var map = new google.maps.Map(this.get(0), $.extend(options, { center: center }));
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results.length) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment