Sencha Touch - 谷歌地图和居中标记 [英] Sencha Touch - Google Map and centering a Marker

查看:122
本文介绍了Sencha Touch - 谷歌地图和居中标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它只是我还是谷歌地图api似乎在古怪的一面?
尝试简单地显示某个坐标的标记,然后将屏幕居中放置在标记上。



在我的控制器中从视图中触发:

(GoogleMap){

 
var lat = record.get(Latitude);

var pos = new google.maps.LatLng(lat,long);

var marker = new google.maps.Marker({
position:pos
});

marker.setMap(googleMap);
googleMap.setCenter(marker.getPosition());
googleMap.setZoom(14);


好像把标记放在屏幕的中心但是当我第二次或第三次返回并显示相同的屏幕时,标记会被添加,但是这次标记不会居中。



有没有人得到这个工作正常?我不认为它是与ST2相关的,但更多的是Google API的怪癖。

解决方案

一个小超时,比它会正常工作。

  setTimeout(function(){
googleMap.panTo(marker。 getPosition());
},100);

我不知道这是否是一个错误,但这种方式显示在展示中。


Is it just me or does the google maps api seem to be on the quirky side? Trying to simply show a marker for some coordinates, and then center the screen on the marker.

In my controller fired from a view:

onGoogleMapRender: function (googleMap) {

        var long = record.get("Longitude");
        var lat = record.get("Latitude");

        var pos = new google.maps.LatLng(lat, long);

        var marker = new google.maps.Marker({
            position: pos
        });

        marker.setMap(googleMap);
        googleMap.setCenter(marker.getPosition());
        googleMap.setZoom(14);

    }

It seems to place the marker in the center of the screen but when I return and show the same screen the 2nd, or 3rd time, the marker is added but this time the marker doesn't get centered.

Has anyone got this working correctly? I don't suppose it is any ST2 related but more a quirk of the google api.

解决方案

You have to center it with a small timeout, than it will work fine.

setTimeout(function() {
    googleMap.panTo(marker.getPosition());
}, 100);

I don't know if it's a bug, but this way is shown in the showcase.

这篇关于Sencha Touch - 谷歌地图和居中标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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