超图---简单地图显示
来源:互联网 发布:软件项目建设规范 编辑:程序博客网 时间:2024/04/30 08:33
最近做了地图的功能,用了超图,就是简单实现显示当前位置。
前期
首先导入超图的sdk,我用的是iclient_android_7.1.0.jar。
权限及布局
网络访问权限:<uses-permission android:name="android.permission.INTERNET" />
GPS定位权限:<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
这是精确定位的权限,如果用到网络定位或基站定位,加入<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.supermap.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:enabled="true" /> <Button android:id="@+id/btn_location" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="10dip" android:background="@drawable/location_marker" /></RelativeLayout>
MapView是图层,在图层上再放置覆盖物,如定位的按钮btn_location。
显示当前位置
主界面:
mapView = (MapView) findViewById(R.id.mapview);LayerView layerView = new LayerView(this); layerView.setURL(Constant.URL_MAP); mapView.setBuiltInZoomControls(true); mapView.addLayer(layerView); final Drawable drawableBlue = getResources().getDrawable(R.drawable.blue_pin); new Handler().postDelayed(new Runnable() { @Override public void run() { LocationUtil.initLocation(mapView, drawableBlue); } }, 2000);
LocationUtil:
public static void initLocation(MapView view, Drawable drawable) { if (view == null) { return; } mapView = view; context = view.getContext().getApplicationContext(); if (context == null) { return; } overlay = new DefaultItemizedOverlay(drawable); if (!mapView.getOverlays().contains(overlay)) { mapView.getOverlays().add(overlay); } // times 用来计数第几次定位 times = 1; mLocationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); gpsListener = new MyLocationListener(); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 3, gpsListener); }
private static class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location location) { Point2D gp = null; String title = "当前位置"; try { gp = new Point2D(location.getLongitude(), location.getLatitude()); overlayItem = new OverlayItem(gp, title, title); overlay.clear(); overlay.addItem(overlayItem); if (times < 2) { mapView.getController().animateTo(gp); mapView.getController().setZoom(mapView.getMaxZoomLevel()); } // 重新onDraw一次 mapView.invalidate(); times++; // Toast.makeText(context, title, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT) .show(); } } @Override public void onProviderDisabled(String arg0) { System.out.println(arg0); } @Override public void onProviderEnabled(String arg0) { System.out.println(arg0); } @Override public void onStatusChanged(String arg0, int status, Bundle arg2) { } }
LayerView是覆盖物图层,防止覆盖物。layerView.setURL(Constant.URL_MAP),放入你的iclient地址。mapView.setBuiltInZoomControls(true);设置可放大缩小。
postDelayed,之所以要延时发送,主要是我在用的时候,发现如果地图图层出不来的话,就永远出不来了,所以认为等待2s,等待地图图层显示出来。
new Point2D(location.getLongitude(), location.getLatitude());生成地图上的二维点。
overlay.addItem(overlayItem);将覆盖物放入覆盖物图层。
mapView.getController().animateTo(gp);设置地图中心点。
mapView.getController().setZoom(mapView.getMaxZoomLevel());设置地图缩放等级。
mapView.invalidate();地图重绘。
这样就简单的实现了超图的定位显示功能,因为百度不到相关资料,所以在这儿分享一下。
- 超图---简单地图显示
- superMAP超图控制TiledDynamicRESTLayer地图图层显示与隐蔽
- 超图的地图慧
- SuperMap超图基础——打开地图
- 超图IClient for Flex加载天地图经纬度地图
- 简单使用百度地图,显示头像
- 百度地图简单基础显示+定位+搜索
- android---高德地图(1)---显示一张简单地图
- 植入百度地图(一)——简单显示地图
- 超图中查询结果的放大显示方式
- 地图显示----地图显示
- supermap objects 编程 显示 地图 (最简单的显示地图代码)
- 百度地图-----显示地图
- 超图使用javascript在地图上标记点,点击时并弹出窗口
- 显示地图
- 显示地图
- 地图显示
- 地图显示
- sed实例精讲
- Nginx上的第一个HelloWorld
- 酷狗2015秋季校园招聘技术开发类笔试题
- Spark GraphX的边构造过程详解——从 RDD[Edge[ED]] 到 EdgeRDD[ED, VD]
- 【读书笔记】iOS网络-解析响应负载
- 超图---简单地图显示
- Self Sizing Cells tableView 自适应高度
- 第八章:ogg初始化datapump
- Unity3D游戏开发之SQLite让数据库开发更简单
- 摘抄
- bind1st和bind2nd函数
- 时光飞逝
- java serializable序列化的作用
- 兼容低版本的 Material Design ProgressBar