问题
Okay, This problem i have been facing for a couple of days now and can't seem to resolve.
This is how my map works:
- Tap on any point on map
- Take photo by camera intent
- return photo as marker (thumbnail) to that specific point tapped.
(all the above works fine)
This is where i am stuck:
Tapping on the marker (image) it should then display larger image of marker as the marker thumbnail is quite small. The problem is it shows the latest image taken and not the image related to that marker. So my question is how can I set a marker id so that when the users taps on that marker to display the full image. I have asked this before here on SO, but had to change my code so that the images are saved in a folder on the device. Also there is a separate class to create the thumbnail. (however i don't think this would make any difference to adding a marker id)
This is the code that works up until the correct image is displayed for the marker. (this just displays the latest image taken):
CAMERA INTENT
Intent getCameraImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
getApplicationContext().getDir(
getResources().getString(R.string.app_name), MODE_PRIVATE);
fileUri = Uri.fromFile(new File((Environment.getExternalStorageDirectory() +
"/" +getResources().getString(R.string.app_name)),new Date().getTime() + ".jpg"));
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(getCameraImage, TAKE_PICTURE);
onActivityResult
if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK) {
try {
GetImageThumbnail getImageThumbnail = new GetImageThumbnail();
bitmap = getImageThumbnail.getThumbnail(fileUri, this);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
{
MarkerOptions markerOptions = new MarkerOptions()
.draggable(true)
.snippet("Tap here to remove marker")
.title("My Marker")
.position(pointtap)
.icon(BitmapDescriptorFactory
.fromBitmap(bitmap));
googleMap.addMarker(markerOptions);
}
}
}
onMarkerClick
@Override
public boolean onMarkerClick(Marker marker) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("My Marker");
// set dialog message
alertDialogBuilder
.setMessage("Select Option")
.setCancelable(false)
.setPositiveButton("Display full Image",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imgUri = Uri.parse("file://" + fileUri);
intent.setDataAndType(imgUri, "image/*");
startActivity(intent);
}
})
.setNegativeButton("Delete Marker",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
marker.remove();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
return false;
I am hoping someone would be so kind to show me how i can implement a marker id so that the image taken for that marker is displayed full screen when the user taps the marker.
Thank you all!
UPDATE Had to implement AlertDialog to display two options, one to delete marker and one to display full image, the display full image is the one i am struggling with to display the image taken at that point on the map.
回答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:
public class CustomInfoWindow implements InfoWindowAdapter {
@Override
public View getInfoContents(Marker marker) {
View v = LayoutInflater.from(AppCtxProv.getContext()).inflate(R.layout.custom_info_window, null);
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
return v;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
}
Then for the custom layout I used this simple code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white" >
<TextView
android: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:
public class AppCtxProv extends Application {
@Override
public void onCreate() {
super.onCreate();
}
public static Context getContext() {
return getApplicationContext();
}
}
And in the manifest just give the
android:name="your.package.AppCtxProv"
attribute to the Application tag
回答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
String mId = 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
来源:https://stackoverflow.com/questions/27446093/setting-id-to-google-map-api-v2-marker-to-return-image-taken-by-camera-intent