Skip to content

Instantly share code, notes, and snippets.

@bencooling
Created August 25, 2015 06:43
Show Gist options
  • Save bencooling/52e35ac7a36dc0669c93 to your computer and use it in GitHub Desktop.
Save bencooling/52e35ac7a36dc0669c93 to your computer and use it in GitHub Desktop.
api | google maps simple
# API: Google maps
## Simple map
<div id="map" class="map"></div>
## Geolocation map
Map centered by address, not latlng
<div id="address" class="map"></div>
##
function initAddress(){
var geocoder = new google.maps.Geocoder();
var address = '1 Moonan Street Maryland, NSW';
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var map = new google.maps.Map(document.getElementById('address'), {
center: results[0].geometry.location,
zoom: 18
});
}
});
}
google.maps.event.addDomListener(window, 'load', initAddress);
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
google.maps.event.addDomListener(window, 'load', initMap);
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
.map {
width: 400px;
height: 200px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment