and*_*nnn 1 android google-maps google-maps-markers
是否可以更加"自动"在地图中添加地理位置?我的意思是,如果我们要在地图中添加许多点(超过100个),我们就不必逐个添加它们:
GeoPoint point2 = new GeoPoint(microdegrees(36.86774),microdegrees(10.305302));
GeoPoint point3 = new GeoPoint(microdegrees(36.87154),microdegrees(10.341815));
GeoPoint point4 = new GeoPoint(microdegrees(36.876093),microdegrees(10.325716));
pinOverlay.addPoint(point2);
pinOverlay.addPoint(point3);
pinOverlay.addPoint(point4);
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以将它们全部存储在一个表中,然后编译器逐个添加它们?
hoo*_*d82 10
您需要将它们存储在SQLite数据库或其他形式的数据存储中,然后您可以将它们拉入并使用ItemizedOverlay将它们放置在地图上,请参阅Google Map View(教程).
从数据库游标创建数组
Cursor cursor = mDbHelper.getItems();
cursor.moveToFirst();
List<CatchItem> catchList = new ArrayList<CatchItem>();
if (cursor != null && cursor.getCount() > 0) {
for (int i = 0; i < cursor.getCount(); i++) {
CatchItem item = new CatchItem();
item.Latitude = cursor.getDouble(cursor.getColumnIndex("latitude"));
item.Longitude = cursor.getDouble(cursor.getColumnIndex("longitude"));
catchList.add(item);
cursor.moveToNext();
}
}
Run Code Online (Sandbox Code Playgroud)
ItemizedOverlay
List<Overlay> overlays = mMaps.getOverlays();
overlays.clear();
CatchesItemizedOverlay catchOverlays = new CatchesItemizedOverlay(getResources().getDrawable(R.drawable.map_markeroverlay_blue72), this);
for (int i = 0; i < catchList.size(); i++) {
double lat = catchList.get(i).Latitude;
double lng = catchList.get(i).Longitude;
GeoPoint geopoint = new GeoPoint((int)(lat*1E6), (int)(lng*1E6));
catchOverlays.addOverlay(new CatchOverlayItem(this, geopoint, catchList.get(i)));
}
overlays.add(catchOverlays);
Run Code Online (Sandbox Code Playgroud)
CatchesItemizedOverlay是我自己的扩展ItemizedOverlay(我需要自定义功能).catchList对象只是一个具有纬度和经度的自定义对象.
希望这适合你.
| 归档时间: |
|
| 查看次数: |
6754 次 |
| 最近记录: |