在谷歌地图会自动添加多个geopoints和标记 [英] Add multiple geopoints and markers automatically in Google Maps

查看:172
本文介绍了在谷歌地图会自动添加多个geopoints和标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能使添加在地图上更自动一个的GeoPoint的?我的意思是,如果我们有很多点,在地图(超过100)增加,我们没有一个像添加它们之一:

Is it possible to make the addition of a geopoint in a map more "automatic"? I mean, if we have many points to add in the map (more than 100), we don't have to add them one by one like that:

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);

有没有一种方法去购买他们都在一个表,然后编译器由一个增加了他们吗?

Is there a method to stock them all in a table and then the compiler adds them one by one?

推荐答案

您会希望将它们存储在任何一个SQLite数据库或其他形式的数据存储,然后你可以拉他们,并把他们在地图上与ItemizedOverlay,看到的 谷歌地图查看 的(教程)。

You'll want to store them in either a SQLite database or some other form of data storage, and then you can pull them in and place them on the map with an ItemizedOverlay, see Google Map View (a tutorial).

创建从一个数据库游标阵列​​

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();
    }
}

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);

CatchesItemizedOverlay 是我自己的扩展 ItemizedOverlay (我需要自定义的功能)。该catchList对象只是具有经度和纬度的自定义对象。

CatchesItemizedOverlay is my own extended ItemizedOverlay (I needed custom functionality). The catchList object is just a custom object that has latitude and longitude.

希望这对你的作品。

这篇关于在谷歌地图会自动添加多个geopoints和标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆