admin管理员组文章数量:1244303
When I initialize google maps in my app, I do something like this:
var myOptions = {
center: new google.maps.LatLng(39.729001, -94.902342),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
setUpMarker(map);
Which works, however, I would need to set up the center of the map and zoom for the specific marker that is created by the function setUpMarker
.
I've tried inside the setUpMarker
function to do this:
fromMarker = new google.maps.Marker({
center: fromLatlng,
zoom: 5,
map: map,
title: "Here"
});
But it didn't help. Thus, how do achieve of this effect?
Thank you guys for help.
When I initialize google maps in my app, I do something like this:
var myOptions = {
center: new google.maps.LatLng(39.729001, -94.902342),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
setUpMarker(map);
Which works, however, I would need to set up the center of the map and zoom for the specific marker that is created by the function setUpMarker
.
I've tried inside the setUpMarker
function to do this:
fromMarker = new google.maps.Marker({
center: fromLatlng,
zoom: 5,
map: map,
title: "Here"
});
But it didn't help. Thus, how do achieve of this effect?
Thank you guys for help.
Share Improve this question asked Jun 29, 2014 at 23:49 user984621user984621 48.5k76 gold badges233 silver badges428 bronze badges 2- 1 A google.maps.Marker object doesn't have those options. If you want to change the center and the zoom of the google.maps.Map you need to call the setCenter and setZoom options on your map. – geocodezip Commented Jun 30, 2014 at 0:06
- Where does fromLatlng e from in your setupMarker function? – geocodezip Commented Jun 30, 2014 at 0:10
1 Answer
Reset to default 10The map object has setZoom() and setCenter() functions for the same. Refer to:
https://developers.google./maps/documentation/javascript/events#MarkerEvents
本文标签: javascriptGoogle Maps APIhow to set center and zoom for current markerStack Overflow
版权声明:本文标题:javascript - Google Maps API - how to set center and zoom for current marker? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740178268a2236841.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论