映射JavaScript API中心问题 [英] Maps javascript api center issue

查看:68
本文介绍了映射JavaScript API中心问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题非常简单。使用以下代码创建地图后,地图的中心位置不正确。

  var myOptions = {
center:new google.maps.LatLng(47.000059,2.06543),
zoom:9,
mapTypeId:google.maps.MapTypeId.ROADMAP,
scaleControl:false,
streetViewControl:false,
mapTypeControl:false,
};
var activity_map = new google.maps.Map(document.getElementById(activity-map),myOptions);

这一点是法国的中间地带。我的div是一个具有隐藏溢出和相对位置的200x200px块。似乎预期的中心位于div的左上角。我已经尝试更改缩放级别,在初始化地图后设置中心,但它不起作用。 解决方案

问题不在于您提供的代码中。 左上角问题是当地图初始化时,包含地图的div没有大小。您尚未提供指定地图大小的HTML / CSS(或者如果最初隐藏地图,则显示它)。



另一种可能性是您正在初始化DOM完全呈现之前的地图,您应该在DOM ready或body onload事件触发后初始化它。


My problem is realy simple. After creating a map by using the following code, the center of the map is not well placed.

var myOptions = {
  center: new google.maps.LatLng(47.000059, 2.06543),
  zoom: 9,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  scaleControl: false,
  streetViewControl: false,
  mapTypeControl: false,
};
var activity_map = new google.maps.Map(document.getElementById("activity-map"), myOptions);

This point is the middle of France. My div is a 200x200px block with an hidden overflow and relative position. It's seems the expected center is placed in the top left and corner of the div. I've already tried to change the zoom level, set the center after initialize the map but it didn't work.

解决方案

The problem is not in the code you provided. The "top left corner" issue is when the div that contains map doesn't have a size when the map is initialized. You haven't provided the HTML/CSS that specifies the size of the map (or that displays it if it is initially hidden).

Another possibility is that you are initializing the map before DOM is completely rendered, you should be initializing it after the DOM ready or body onload event fires.

这篇关于映射JavaScript API中心问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆