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

javascript - Google Maps API - how to set center and zoom for current marker? - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 10

The map object has setZoom() and setCenter() functions for the same. Refer to:

https://developers.google./maps/documentation/javascript/events#MarkerEvents

发布评论

评论列表(0)

  1. 暂无评论