Created
April 18, 2011 06:18
-
-
Save jywarren/924884 to your computer and use it in GitHub Desktop.
Live URL hash updating as you drag a Google Map around. That way the URL is always the permalink for your current viewport.
This file contains 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
function makeLink() { | |
location.hash = "#/"+map.getCenter().lat().toFixed(3)+"/"+map.getCenter().lng().toFixed(3)+"/"+map.getZoom(); | |
} | |
function initialize() { | |
var query = location.search.substring(1); | |
var lat = 0.5; | |
var lng = 0.5; | |
var zoom = config.defaultZoom; | |
// Jeff's hash rewriting: | |
var hash = window.location.hash | |
var params = hash.split("/") | |
if (params.length > 1) { | |
lat = parseFloat(params[1]) | |
lng = parseFloat(params[2]) | |
zoom = parseInt(params[3]) | |
} | |
var mapOptions = { | |
zoom: zoom, | |
center: new google.maps.LatLng(lat, lng), | |
navigationControl: true, | |
scaleControl: false, | |
mapTypeControl: mapTyepControlToggle, | |
mapTypeControlOptions: { | |
mapTypeIds: mapTypeIds | |
}, | |
mapTypeId: mapTypeIdDefault, | |
streetViewControl: false, | |
backgroundColor: config.bg_color, | |
}; | |
map = new google.maps.Map(document.getElementById('mcmap'), mapOptions); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment