Google Map V3不居中,仅显示地图的一部分 [英] Google Map V3 not centering, displays only part of map

查看:135
本文介绍了Google Map V3不居中,仅显示地图的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone开发基于jQTouch的应用程序,其中一部分使用Google Maps API(V3)。我希望能够将地理位置坐标传递给地图,并使用标记将其置于中心位置。我现在得到的是适当缩放级别的地图,但所需的中心点出现在右上角。它也仅显示地图区域的大约三分之一(其余为灰色),并且当您平移或缩放时它的行为有些不规律。这是代码:

I'm developing a jQTouch-based app for the iPhone and part of it uses the Google Maps API (V3). I want to be able to pass the geolocation coordinates to the map and have it center the location with a marker. What I'm getting now is the map at the proper zoom level but the desired center-point appears in the upper-righthand corner. It's also showing only about a third of the map area (the rest is gray) and it behaves somewhat erratically when you pan or zoom. Here's the code:


var coords = { latitude : "35.510630", longitude : "-79.255374" };
var latlng = new google.maps.LatLng(coords.latitude, coords.longitude);
var myOptions = {
    zoom: 12,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($("#map_canvas").get(0), myOptions);
var marker = new google.maps.Marker({
    position: latlng, 
    map: map, 
});     

BTW:它在其他平台/浏览器上的外观和行为也一样。

BTW: It looks and behaves the same on other platforms/browsers as well.

想法?

提前致谢,

Mark

已添加
这是一个链接,可以准确显示正在发生的事情:
iPhone模拟器的屏幕截图

推荐答案

我猜猜你正在使用AJAX来显示地图,或者在某个时刻隐藏地图然后根据动作显示它?

I'm guessing you're using AJAX to display the map, or have the map hidden at some point and then display it based on an action?

在这种情况下Google不会我不知道地图容器的大小,它只会绘制地图的一部分,通常偏离中心。

In this case Google doesn't know the size of the map container and it will draw only part of the map, usually off-centered.

要解决此问题,请调整地图大小,然后重新以lat / lng为中心。这样的事情:

To fix this, resize the map, then re-center on your lat/lng. Something like this:

google.maps.event.trigger(map, 'resize');

// Recenter the map now that it's been redrawn               
var reCenter = new google.maps.LatLng(yourLat, yourLng);
map.setCenter(reCenter);

这篇关于Google Map V3不居中,仅显示地图的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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