Вопрос

I am a student in china . and when use the gmap4rails gem I have one problem.I want to set the mao center and zoom like the official guide offer
https://developers.google.com/maps/documentation/javascript/tutorial?#HelloWorld so I code like the picture shows.but it doesn't work. and google the question but didn't get the answer.what is more ,i want set the language to chinese I just like do like this but It didn't work.

var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8
};
handler = Gmaps.build('Google',mapOptions);

can you help me?

Это было полезно?

Решение

You should do:

var mapOptions = {
  center: new google.maps.LatLng(-34.397, 150.644),
  zoom: 8
};
handler = Gmaps.build('Google');
handler.buildMap( {provider: mapOptions, internal: {id: 'map'}}, function(){
  //code to add overlays etc... here
});

Or:

handler = Gmaps.build('Google');
handler.buildMap( {internal: {id: 'map'}}, function(){
  // handler.map is the proxy object created by the gem, 
  // where you can add your custom methods,
  // like centerOn
  handler.map.centerOn([-34.397, 150.644]);

  // handler.getMap() is the google map object
  // you can also access it with handler.map.getServiceObject()
  handler.getMap().setZoom(8);
});

It's important to pass the id of the div where you want the map to appear.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top