gpt4 book ai didi

android - 在 MapView 上获取坐标,适用于 Titanium Appaccelerator 上的 Android

转载 作者:搜寻专家 更新时间:2023-11-01 08:55:13 24 4
gpt4 key购买 nike

我正在尝试获取 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};

如果我不移动 map 的位置(就在程序启动时),这会很好地工作。但是,如果我将 map 移动到其他位置,则不会更新可变区域。它总是相同的(纬度:37.390749,经度:-122.081651)

如何获取更新后的坐标?

最佳答案

解决了!

这个值显然并不意味着每次你在 map 上移动时都不会改变。您可以创建一个方法来使用以下方法更新这些变量:

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 文件的顶部。另外你需要告诉 map 调用函数 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"行。

关于android - 在 MapView 上获取坐标,适用于 Titanium Appaccelerator 上的 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19510730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com