Skip to content

Instantly share code, notes, and snippets.

@jywarren
Created April 18, 2011 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jywarren/924884 to your computer and use it in GitHub Desktop.
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.
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