Setting Id To Google Map Api V2 Marker To Return Image Taken By Camera Intent
Solution 1:
If you are not using the markers InfoWindow you could set the InfoWindows title or snippet to your id and then retrieve it. I do this with
myMap.addMarker(new MarkerOptions()
.title(myTitle)
.snippet(mySnippet)
.position(myPosition));
Then to retrieve the id just use:
myMarker.getTitle()
or
myMarker.getSnippet()
Here is the example to use the snippet as a tag for the marker:
publicclassCustomInfoWindowimplementsInfoWindowAdapter {
@Overridepublic View getInfoContents(Marker marker) {
Viewv= LayoutInflater.from(AppCtxProv.getContext()).inflate(R.layout.custom_info_window, null);
TextViewtitle= (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
return v;
}
@Overridepublic View getInfoWindow(Marker marker) {
returnnull;
}
}
Then for the custom layout I used this simple code:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@color/white" ><TextViewandroid:id="@+id/title"android:layout_width="wrap_content"android:layout_height="wrap_content" /></RelativeLayout>
The AppCtxProv is an Activity class I created that just returns the context:
publicclassAppCtxProvextendsApplication {
@OverridepublicvoidonCreate() {
super.onCreate();
}
publicstaticContextgetContext() {
returngetApplicationContext();
}
}
And in the manifest just give the
android:name="your.package.AppCtxProv"
attribute to the Application tag
Solution 2:
Try with this..
( ref.How to remove marker from google map v2? )
Previously I did told you..Just save marker to your own variables.. and there are a Index number for each and every marker..Hence Index number is provided by you and Google-Marker have itself ID... Google-Marker return ID with 'm1, m2 or m3...'.. so just replace get marker.getId and replace 'm'.. Now you can get marker this Id do match with your Index number.
// Sample code to get marker id
StringmId = marker.getId();
mId = mId.replace("m","");
String clickMarker = Integer.valueOf(mId);
// hence 'i' is Google-Marker Id... and You have your marker Index value.. match with it. // sample code to get Click marker Id
for(int k = 0; k<myMarkersHash.size(); k++)
{
if(clickMarker == myMarkersHash.get(k))
{
// now got k is marker value
break;
}
}
// myMarkersHash defined also at ref. link
Post a Comment for "Setting Id To Google Map Api V2 Marker To Return Image Taken By Camera Intent"