查找路线起点和终点的地址
我正在 android 中使用 KML 文件通过 DDMS 接收 GPS 数据,并且使用以下代码:
public class screen4 extends MapActivity
{
List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen4);
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
mapView = (MapView) findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
}
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
latitude=(int)(loc.getLatitude()* 1E6);
longitude=(int)(loc.getLongitude()* 1E6);
GeoPoint p = new GeoPoint(latitude,longitude);
geoPointsArray.add(p);
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
mapView.setSatellite(true);
}
}
在 onLocationChanged() 中,我检索 GPS 数据并将其存储在 GeoPoint p 中,我想要做的是找出地址我检索 GPS 数据的第一个点(纬度、经度)和最后一个点。
我的问题是:
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
在检索到所有 GPS 数据之前,我的程序是否会在这一行保持阻塞状态?
通过这种方式,我可以为 geoPointsArray(0) 应用地理编码器,然后为 geoPointsArray(maxSize) 应用地理编码器。
我的问题是我不知道这个程序是如何工作的,所以我无法真正弄清楚何时检索到我的所有 GPS 数据(我的 geoPointsArray 已满)以及在哪里应用地理编码器。
问题2:
当我开始接收位置更新时,我想连接到远程服务器并将存储在geoPointArray中的所有GPS数据发送到服务器。知道我应该从哪里开始我的线程吗?我有一堆代码行,但我想没有人会读它!
I'm receving GPS data via DDMS using a KML file in android and I'm using the following code:
public class screen4 extends MapActivity
{
List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen4);
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
mapView = (MapView) findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
}
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
latitude=(int)(loc.getLatitude()* 1E6);
longitude=(int)(loc.getLongitude()* 1E6);
GeoPoint p = new GeoPoint(latitude,longitude);
geoPointsArray.add(p);
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
mapView.setSatellite(true);
}
}
In onLocationChanged() I retrieve the GPS data and store it in GeoPoint p, what I want to do is to find out the address of the first point(latitude,longitude) and of the last point whose GPS data I retrieve.
My question is: Does my program stay blocked at this line:
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
until all the GPS data is retrieved?
In this way I can apply Geocoder for the geoPointsArray(0) and after that for geoPointsArray(maxSize).
My problem is that I don't know how this program works,so I can't really figure out when all my GPS data is retrieved(my geoPointsArray is full) and so where to apply Geocoder.
Question2:
In the moment I start to receive location updates I want to connect to a remote server and send all the GPS data that is stored in geoPointArray to the server. Any idea of where should I start my thread? I have a bunch of code lines but I guess no one is going to read that!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会。位置更新是异步的。
No. Location updates are asynchronous.