你有两种方式确定用户的当前位置:
使用以下代码:
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE, new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } public void onLocationChanged(Location location) { // Handle location change here } });
MapWidget使用Network location provider ,以便快速定位,或者使用GPS location provider
下面是如何使用监听器的示例:
private void initListeners() { mapWidget.setOnLocationChangedListener(new OnLocationChangedListener() { public void onLocationChanged(MapWidget v, Location location) { Layer layer = v.getLayerById(LAYER_ID); MapObject object = layer.getMapObject(OBJECT_ID); object.moveTo(location); } }); }
private void configureMapWidget() { GPSConfig gpsConfig = mapWidget.getGpsConfig(); gpsConfig.setGPSUpdateInterval(MIN_TIME_INTERVAL, MIN_DISTANCE_IN_METERS); }
原文链接:http://www.67tgb.com/?p=604
转载注明:望月听涛
限于篇幅,就不在一一贴了,更多文章参见:
基于mAppWidget实现手绘地图(九)–如何处理地图对象的touch事件
基于mAppWidget实现手绘地图(十)–在放大前后执行一些操作
基于mAppWidget实现手绘地图(十一)–移动地图到某个坐标