最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Maps API: Get url for current view - Stack Overflow

programmeradmin8浏览0评论

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 );

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 );
Share Improve this question asked Dec 20, 2010 at 22:47 PherrymasonPherrymason 8,0888 gold badges40 silver badges58 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

发布评论

评论列表(0)

  1. 暂无评论