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

本文标签: javascriptGoogle Maps APIhow to set center and zoom for current markerStack Overflow