Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API: Get url for current view

I have a form where users can introduce google maps urls to specify the address of some stuff. I've been thinking in showing a map through Google Map API v3, letting user move to desired location and through a button or something automatically get the url of the place and copy it to an input.

I've been able to display the map using the tutorial, but I haven't been able to find in the documentation how I could get the url...

I think you will not need it, but this is the simple code I'm using:

var latlng = new google.maps.LatLng(-34.397, 150.644);
var options = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false
};
var map = new google.maps.Map(document.getElementById('map-box'), options );
like image 338
Pherrymason Avatar asked Dec 20 '10 22:12

Pherrymason


People also ask

Is Google Maps API no longer free?

Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).


1 Answers

I'd suggest using map.getCenter().toUrlValue() and map.getZoom() to obtain the centre and zoom state of the current map view. That information should let you build a URI that you can then use, bare in mind that you'll need to write some code to take the values off the URI and pass them to the map API.

like image 98
Jonathan Avatar answered Oct 31 '22 12:10

Jonathan