【问题标题】:Getting coordinates on MapView, for Android on Titanium Appaccelerator在 MapView 上获取坐标,适用于 Titanium Appaccelerator 上的 Android
【发布时间】:2013-10-22 06:37:49
【问题描述】:

我正在尝试获取 Titanium MapView(在 Android 上运行的应用)的纬度/经度坐标。

我的 index.xml 上有以下代码:

<Alloy>
    <Window id="win">           

        <View id="mapview" ns="Ti.Map" onClick="doClick" onComplete="setRegion"
            animate="true" regionFit="true" userLocation="true"
            onLongpress="lngPress"
            mapType="Ti.Map.STANDARD_TYPE" >

            <Annotation id="mountainView"
              latitude="37.390749" longitude="-122.081651"
              title="Appcelerator Headquarters" subtitle="Mountain View, CA"
              pincolor="Titanium.Map.ANNOTATION_RED"
              leftButton="/images/appcelerator_small.png"
              myid="1"/>
        </View>
    </Window>
</Alloy>

在我的 index.js 上,我有以下功能:

 function lngPress(evt) {

    var region = $.mapview.getRegion();
    alert('regionlat' + region.latitude + '&' + region.longitude);
    //alert('LongPress' + lat + '&' + lon);
}


$.mapview.annotations = [$.mountainView];
$.mapview.region = {latitude:37.390749, longitude:-122.081651, latitudeDelta:0.01, longitudeDelta:0.01};

如果我不移动地图的位置(就在程序启动时),这可以正常工作。但是,如果我将地图移动到其他位置,则不会更新可变区域。总是一样的(纬度:37.390749,经度:-122.081651)

如何获取更新后的坐标?

【问题讨论】:

    标签: android google-maps titanium


    【解决方案1】:

    解决了!

    该值显然并不是每次您在地图上移动时都会改变。您可以使用以下方法创建更新这些变量的方法:

    function rgnChanged(evt)
    {
        //alert('map moved');
        Ti.App.currentLat = evt.latitude;
        Ti.App.currentLon = evt.longitude;
    }
    

    这里 Ti.App.currentXXX 是全局变量定义为:

    Ti.App.currentLat = 20;
    Ti.App.currentLon = 10;
    

    在 .js 文件的顶部。另外你需要告诉地图调用函数rgnChanged,新的index.xml是这样的(翻录非重要部分):

      <View id="mapview" ns="Ti.Map" onClick="doClick" onComplete="setRegion"
          animate="true" regionFit="true" userLocation="true"
          onLongpress="lngPress" onRegionChanged="rgnChanged"
          mapType="Ti.Map.STANDARD_TYPE" >
    
          <Annotation id="mountainView"
            latitude="37.390749" longitude="-122.081651"
            title="Appcelerator Headquarters" subtitle="Mountain View, CA"
            pincolor="Titanium.Map.ANNOTATION_RED"
            leftButton="/images/appcelerator_small.png"
            myid="1"/>
      </View>
    

    注意 onRegionChanged="rgnChanged" 行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 2011-02-25
      相关资源
      最近更新 更多