1

I'm creating an map that shows a result from a Parse query. I can pass information directly into the marker, such as a title or a lat/long, but I would like to include some additional information (not to be displayed) that I can use when the user clicks on the marker. For instance when the user clicks on the marker, I would like to find the user's objectId from the Parse query (which is simply a string). I've tried the following code in the marker onClickListener to put the string in as an argument:

destPosition = marker.getPosition();
destLat = destPosition.latitude;
destLong = destPosition.longitude;
MarkerDialogFragment markerDialogFragment = new MarkerDialogFragment();
Bundle args = new Bundle();
args.putString("id", marker.getId());
args.putString("userId", userId);
args.putString("title", marker.getTitle());
args.putDouble("latitude", destLat);
args.putDouble("longitude", destLong);
markerDialogFragment.setArguments(args);

when I try to extract this data on the "other side" by getting the arguments, the userId always comes across as null...I've defined userId as such:

 final String userId = parseUsers.get(i).getObjectId();

I've even tried hard coding the string in userId as such, and it still comes back as null when I try to get the arguments:

 final String userId = "test userId";

Here is the get arguments code for the marker onCreateDialog method:

builder = new AlertDialog.Builder(getActivity());
    final String markerId = getArguments().getString("id");
    final String userId = getArguments().getString("userId");
    final String title = getArguments().getString("title");
    final double destLat = getArguments().getDouble("latitude");
    final double destLong = getArguments().getDouble("longitude");        
    builder.setTitle(title)

When I use the debugger to stop the code to see the values, all data is set as expected and I have values for each item EXCEPT the userId. Can anyone help point me in the right direction? I simply want to pass a value associated with a variable and have it be tied to each marker created on the map. Thanks!

Wayne Johnson
  • 214
  • 3
  • 18
  • I am trying to embed a reference ID to a marker info window. When a user clicks on the info window, it should pass the reference ID to a new intent. I can pass the string I want in a snippet, but I don't want the user to actually see that information – Wayne Johnson Oct 13 '15 at 06:35

1 Answers1

0

You cannot add anymore data to the marker. So if you want to add more data to your marker, you will have to store it in an external variable with marker's ID (getID())

eg -

HashMap<int,Object> extramarkerData = new HashMap<int,Object>();

and put data into hashmap

extramarkerData.put(marker.getId(),"additional data");
Gaurav
  • 3,615
  • 2
  • 27
  • 50
  • Okay, so if I create the hashmap to store this data, how will I extract this data on the "other side", when I'm trying to get this data out to query the additional data? I'm assuming there is some sort of extramarkerData.get(marker.getId()) function? – Wayne Johnson Oct 13 '15 at 17:15
  • exactly to retrieve data you have to use: `extramarkerData.get(marker.getId()) function` – Gaurav Oct 14 '15 at 04:58
  • Thank you so much. I searched for several hours and was only finding information about how to customize the window. This works perfectly, thank you! – Wayne Johnson Oct 15 '15 at 00:55
  • Okay, this works within the same class... is there a way to store this data in the hashmap in one class, say the MapActivity, then extract the data in a dialog fragment or any other fragment/activity? – Wayne Johnson Oct 16 '15 at 03:05
  • Yes declare the Hashmap into Application class refer http://stackoverflow.com/questions/18002227/why-extend-an-application-class & IntelliJ Amiya 's answer to know how to create extends Application Class also make entry into manifest.xml – Gaurav Oct 16 '15 at 06:21