-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyItemizedOverlay.java
More file actions
executable file
·64 lines (52 loc) · 1.88 KB
/
MyItemizedOverlay.java
File metadata and controls
executable file
·64 lines (52 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package net.learn2develop.maps;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
//---array of OverlayItem objects---
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public MyItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
//---add an OverlayItem object to the map---
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
//---call this to draw the OverLayItem objects---
populate();
}
//---remove an OverlayItem object from the map---
public void removeOverlay(OverlayItem overlay) {
mOverlays.remove(overlay);
//---call this to draw the OverLayItem objects---
populate();
}
//---called when populate() is called; returns each OverlayItem object
// in the array---
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
//---returns the number of OverlayItem objects---
@Override
public int size() {
return mOverlays.size();
}
//---called when the user taps on the OverlayItem objects---
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}