Google Maps API - 奇怪地图“偏移”行为 [英] Google Maps API - Strange Map "Offset" Behaviour

查看:221
本文介绍了Google Maps API - 奇怪地图“偏移”行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页上在表单旁边添加地图。这个想法是,人们可以注册,当他们输入他们的地址并点击搜索,它的地方标记他们的房子,他们必须这样做之前,他们提交表单(地理位置在我的网站上有很大的作用)。

I'm adding a map next to a form on my web page. The idea is that people can sign up, and when they type in their address and click search, it place-marks their house, they must do this before they submit the form (geolocation has a large role on my site).

不幸的是,我已经添加了地图,但在地图窗口中,地图本身似乎是偏移的。请参阅下面的图片来说明我的意思:

Unfortunately, I have added the map, but within the map window the map itself appears to be offset. See the image below to illustrate what I mean:

我只能从框的映射部分中拖动地图。如果我选择灰色区域拖动地图,那么它会失败。

I can only drag the map from within the "mapped" part of the box. If I select the grey area to drag the map around, it fails.

任何想法会导致什么?

EDIT:

这是我的地图初始化Javascript,在网页加载时调用。

Here is my map-initialising Javascript, called on page load.

    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(52.428385,-3.560257);
    var myOptions = {
      zoom: 7,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("adminMap"), myOptions);

这是我的地图CSS

#adminMap{
    float:left;
    width:270px;
    height:370px;
    margin-left:20px; 
}

这是我的地图HTML

Here is my map HTML

<div id="adminMap">
</div>


推荐答案

没有访问任何代码,我最好的打赌是,当容器 div 被隐藏时,映射被初始化。我已经看到造成这种症状。尝试设置您的地图,因为你显示它,而不是之前。

I've seen things similar to this. Without access to any code, my best bet is that the map is initialized at a time when the container div is hidden. I've seen that cause such symptoms. Try to set up your map as you're showing it, rather than before.

这篇关于Google Maps API - 奇怪地图“偏移”行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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