How to manage Markers well using google maps api v2 on android

Kostek

I'm trying to implement app in which you can add your own marker which will be given a shutdown time. To do so I need to know how to manage my markers. Let's say I have array list of users with assigned unique ID.

    private ArrayList<User> userList = new ArrayList<>();

Then I will create array list of markers which will contain information like Latitude, Longitude, Title, owner's ID and deadline.

    private ArrayList<MyMarker> mMarkersArray = new ArrayList<MyMarker>();

Next whenever user will activate add marker method, new marker will be pushed to my list of markers. Ideologically everything seems nice and easy, furthermore creating new object looks like this:

    Marker mMarker = mMap.addMarker(new MarkerOptions() (...) );

but when it comes to managing specific markers it seems like I'm missing something. There will be some trigger method which will check the deadline of all markers (or rather first one on the 'sorted by deadline' list) and then it should remove (not hide, because I think it would be inefficient from the memory point of view). How to achieve this? I can't add some custom variable like ID to markers (so I could then find the one I'm interested in) and I'm a bit lost.

There is a way to achieve this by clearing whole map and then rendering again all markers except the inactive, but as far as I'm concerned it's very inefficient and there has to be better solution.

ztan

If you want to remove a specific marker from the map, you can just call the remove(). method.

Sample code to remove a marker from MapView and HashMap:

 for (Marker marker : hm.keySet()) {
      if (hm.get(marker).equals(deadline)) {
        marker.remove();
        hm.remove(marker);
      }
  }

You dont need to clear the entire MapView, if you just call remove() method on specific marker.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Google Maps Android API v2

分類Dev

Google map API v2 Android - Markers & scale

分類Dev

Google Maps Android API v2 Authorization failure

分類Dev

Can't connect to Google Maps Api Android V2

分類Dev

Overlay an image on google maps android api v2

分類Dev

Adding Multiple Markers in real time google maps v2 android

分類Dev

How to set api key for Google maps v2

分類Dev

Google Map API V3 - infowindows @ markers on 2 maps

分類Dev

Get Markers Addresses in Input fields using Drag-able Google Maps API V3

分類Dev

Setting listeners to groups of markers using Google Maps API

分類Dev

How to change Language on Android google map V2 api

分類Dev

How to hide/show groups of markers by category with Google Maps in Android?

分類Dev

Android 2.3およびgoogle maps API v2

分類Dev

Android Google Maps API v2:方位位置を取得する

分類Dev

How to clear Google map v2 except few markers?

分類Dev

How to animate the camera to a specified location in Google Maps v2 for Android?

分類Dev

Google maps API markers content hide by default

分類Dev

Google Maps V2 - API key not found Error Message

分類Dev

Google Maps Activity V2 Android Studio

分類Dev

android maps api v2 adding multiple circles

分類Dev

Google android maps api v2マーカータイトルを常に表示

分類Dev

How to download and use offline maps in Map API V2?

分類Dev

How to apply CSS to Here Maps API Markers

分類Dev

Map markers not rendering - Google Maps Javascript API v3 In Phonegap

分類Dev

How to manage click on marker which is not in Cluster in Android Google Map API?

分類Dev

Google Maps API 3 - Show All Markers on Screen, but Keep Centerpoint

分類Dev

Google Maps Android API v2のMapFragmentにカスタムコントロールを追加する方法

分類Dev

Google Maps Android API V2で白地図しか入手できないのはなぜですか?

分類Dev

displaying Google Maps API v2 on real device/emulator. can't figure out error

Related 関連記事

  1. 1

    Google Maps Android API v2

  2. 2

    Google map API v2 Android - Markers & scale

  3. 3

    Google Maps Android API v2 Authorization failure

  4. 4

    Can't connect to Google Maps Api Android V2

  5. 5

    Overlay an image on google maps android api v2

  6. 6

    Adding Multiple Markers in real time google maps v2 android

  7. 7

    How to set api key for Google maps v2

  8. 8

    Google Map API V3 - infowindows @ markers on 2 maps

  9. 9

    Get Markers Addresses in Input fields using Drag-able Google Maps API V3

  10. 10

    Setting listeners to groups of markers using Google Maps API

  11. 11

    How to change Language on Android google map V2 api

  12. 12

    How to hide/show groups of markers by category with Google Maps in Android?

  13. 13

    Android 2.3およびgoogle maps API v2

  14. 14

    Android Google Maps API v2:方位位置を取得する

  15. 15

    How to clear Google map v2 except few markers?

  16. 16

    How to animate the camera to a specified location in Google Maps v2 for Android?

  17. 17

    Google maps API markers content hide by default

  18. 18

    Google Maps V2 - API key not found Error Message

  19. 19

    Google Maps Activity V2 Android Studio

  20. 20

    android maps api v2 adding multiple circles

  21. 21

    Google android maps api v2マーカータイトルを常に表示

  22. 22

    How to download and use offline maps in Map API V2?

  23. 23

    How to apply CSS to Here Maps API Markers

  24. 24

    Map markers not rendering - Google Maps Javascript API v3 In Phonegap

  25. 25

    How to manage click on marker which is not in Cluster in Android Google Map API?

  26. 26

    Google Maps API 3 - Show All Markers on Screen, but Keep Centerpoint

  27. 27

    Google Maps Android API v2のMapFragmentにカスタムコントロールを追加する方法

  28. 28

    Google Maps Android API V2で白地図しか入手できないのはなぜですか?

  29. 29

    displaying Google Maps API v2 on real device/emulator. can't figure out error

ホットタグ

アーカイブ