I. 利用Android的辅助功能

定位服务

在移动设备上,定位几乎已经是一个必不可少的功能了。在Android中,设备可以通过GPS、移动通讯网络、WIFI网络来进行定位,这些定位功能都被分装在一个LocationManager对象中,我们可以这样来使用Android的定位服务:

public class AgsLocation extends Activity {

MapView map = null;

LocationManager loc = null;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

map = (MapView) findViewById(R.id.map);

loc = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

loc.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,

new LocationListener() {

public void onLocationChanged(Location l) {

Point ptLatLon = new Point(l.getLongitude(), l

.getLatitude());

SpatialReference sr4326 = SpatialReference.create(4326);

Point ptMap = (Point)GeometryEngine.project(ptLatLon, sr4326,

map.getSpatialReference());

map.centerAt(ptMap);

}

public void onProviderDisabled(String provider) {

}

public void onProviderEnabled(String provider) {

}

public void onStatusChanged(String provider, int status,

Bundle extras) {

}

});

}

}

在代码中我选择了使用GPS定位,注意,要使用Android系统的定位服务(LOCATION_SERVICE),在Android清单文件中一定要有相应的权限:

<manifest ... >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
</manifest>

从Android定位服务中获取到的是经纬度信息,我还需要将这个坐标投影到地图上,这里GeometryEngine又派上用场了。好了,现在让我们用Emulator Control来模拟一个GPS信号发送到模拟器:

这是北京的大致位置,在上面的代码中我们希望地图可以以这个坐标为中心点来进行居中,实际的情况与这个预期是一致的:

图 37 模拟GPS定位到北京附近

II. 附录

在线资源:

ArcGIS for Android(Resource Center):

http://help.arcgis.com/en/arcgismobile/10.0/apis/android/help/

ArcGIS Android API参考:

http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/index.html

本文在线地址:

http://blog.csdn.net/warrenwyf/category/784554.aspx

更多相关文章

  1. 第十七章 Android(安卓)常见的Service
  2. android 进程之间通信--Android(安卓)使用【AIDL】调用外部服务
  3. Android中的IPC方式(二)
  4. Android多进程总结一:生成多进程(android:process属性)
  5. 《Android和PHP开发最佳实践》迷你书
  6. Android-View的滑动
  7. init进程【4】——属性服务
  8. Android中MaterialDesign使用 (五)自定义Behavior实现UC顶栏效果
  9. 【Android】IPC、AIDL、Binder

随机推荐

  1. Android(安卓)Binder框架实现之Framework
  2. 【摘录】ubuntu (10.04)上安装google and
  3. android achartengine实时柱状图例子
  4. Android中使用Android studio生成正式签
  5. Android屏幕及view的截图实例详解
  6. android 限制编辑框输入中文
  7. [读书笔记]Android LayoutInflater.infla
  8. android stagefright框架(一)Video Playbac
  9. android 开发:保存图片到SD卡上
  10. Cheatsheet: 2013 11.12 ~ 11.30