【问题标题】:Set Sencha Touch Map Location设置煎茶触摸地图位置
【发布时间】:2013-04-30 17:03:26
【问题描述】:

设置煎茶触摸地图位置

大家好,我想简单地将 Sencha Touch 2 地图对象设置为特定的邮政编码。我将配置设置为 {useCurrentLoction: true} 工作正常,但经过数小时的研究,我似乎无法找到一种方法来告诉地图对象重新定位到另一个城市,或地址或特别是邮政编码的其他地方我们。

看起来 Google API 具有这些功能,但其中包括:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>

无法识别 Google 在其文档中使用的 api 调用。 Google 说要获取 API 访问密钥,但这需要从多个位置运行,所以我希望无需获取密钥即可实现这一目标。

是否有人能够使用上述访问的 API (maps.google.com/maps/api/js?sensor=true) 重新定位 Sencha Touch 2 地图对象?

谢谢!

【问题讨论】:

  • 你能把你的示例代码贴上来看看如何帮忙

标签: map touch extjs


【解决方案1】:

只需在您的 HTML 文件中包含 &lt;script src="http://maps.google.com/maps/api/js?sensor=true"&gt;&lt;/script&gt;

然后在您的视图中创建一个 xtype 映射,然后在侦听器中添加一个像这样绘制的事件:

listeners: 
{
    painted: function( component, eOpts ) {
        console.log("Entered paint");
        gotoAddress();
        var map = Ext.getCmp('mymap');
        map.setMapCenter(addr);
    }
}  

// Location function add the parameter as desired address to navigate.
// This also includes showing mapper and info window

function gotoAddress() {

    var address = "enter the address required";
    var map = Ext.getCmp('mymap');

    var geocoder = new google.maps.Geocoder();    
    geocoder.geocode( { 'address': address}, function(results, status) {      
        if (status == google.maps.GeocoderStatus.OK) {

            addr= results[0].geometry.location;
            map.setMapCenter(results[0].geometry.location);

            marker.setMap(map.getMap());
            marker.setPosition(results[0].geometry.location);

            infowindow.setContent(address);

            infowindow.open(map.getMap(),marker);

        } else {
          alert('Sorry Address could not be traced: ' + status);
        }
    });
}

注意:Paint 是每次您导航到使用地图的页面时都会调用的事件。当你创建这个页面时,初始化事件只会被创建一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多