What arguments can I include with a map marker - android

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!

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");

Related

Android Extract a specific value from a ListView item

I'm working on an application where I have a ListView that shows the coordinates of my smartphone's position previously stored on a database. The rows of the ListView appear to be like: (latitude, longitude), date.
Is it possible to get the single values of the item? I was thinking to retrieve only the latitude and longitude values of the clicked item so that I can open a new MapsActivity that sets a marker at those specific coordinates.
Looking through other similar questions I've got that with ((TextView) view).getText() or with listView.getItemAtPosition(position) I can read the entire content of the item, but I'd like to apply that to the first two values of the ListView.
So for anyone interested I solved my problem by parsing the content of the item as a String by doing like this:
String str = (String) listView.getItemAtPosition(position);
String parts[] = str.split(",");
String lat = parts[0];
String lon = parts[1];
I had to get rid of "(" and ")" in the visualization of the coordinates as they were hindering the string parsing.

How to perform addition operation using the hash map

HASH MAP
How to perform the addition when an hash map getting an input from the user
through the Edit text in android
final HashMap map = new HashMap<>();
map.put("input1", data1.getText().toString());
map.put("input2", data2.getText().toString());
map.put("input3", data3.getText().toString());
and i want to store and view the value in textview
I Didn't Get What you want
You have to convert that into Integers usingInteger.parseInt(data(x).getText.toString())
You can use HashMap.get() method
Do it with your own logic
I Guess It is Like this:
Integer Sum = ((map.get("input1")) + (map.get("input2")) + (map.get("input3")))

Passing a parse query to another activity?

ParseRelation<ParseObject> p = country.getRelation("view");
ParseQuery P2 = p.getQuery();
So is it possible to intent the P2 query in the next activity ,so that we can use this query in next activity to fetch the data from parse database.
Sadly ParseObject is not parcelable, which would solve hundreds of issues I had with their Android SDK.
But you can surely pass country through its object id.
// Launching...
Intent i = new Intent(context, Destination.class);
i.putExtra(“relationObjectId”, country.getObjectId());
i.putExtra(“relationFieldName”, “view”);
startActivity(i);
// Then in Destination activity..
Intent i = getIntent();
String relationObjectId = i.getStringExtra(“relationObjectId”);
String relationFieldName = i.getStringExtra(“relationFieldName”);
Country country = ParseObject.createWithoutData(Country.class, relationObjectId);
ParseQuery query = country.getRelation(relationFieldName);
Please note that before calling getRelation() again, you might have to use fetchIfNeededInBackground().

How to avoid overwriting of data in firebase

This is my code for adding records in Firebase. there's variable outside called restauCount valued (int) as 1
public void sendMessage(){
int restauCount = 1;
String identifier ="Restaurant" + restauCount;
Firebase userRef = firebaseRef.child("Caloocan");
EditText nameInput = (EditText) findViewById(R.id.nameTxt);
String name = nameInput.getText().toString();
EditText locInput = (EditText) findViewById(R.id.locationTxt);
String location = locInput.getText().toString();
EditText typeInput = (EditText) findViewById(R.id.typeTxt);
String foodtype = typeInput.getText().toString();
if (!name.equals("")){
Map<String, String> caloocan = new HashMap<String, String>();
caloocan.put("resname", name);
caloocan.put("resloc", location);
caloocan.put("foodtype", foodtype);
Map<String, Map<String, String>> users = new HashMap<String, Map<String, String>>();
users.put(identifier,caloocan);
userRef.setValue(users);
restauCount++;
}
}
When i run the sendessage() again. i will type in the fields and when i click ADD which is the sendMessage it will be added in FireBase , however when i add new data. IT OVERWRITES THE OLD DATA INPUTTED ? HOW CAN I ADD MULTIPLE DATA IN FIREBASE WITHOUT OVERWRITING THE DATA?
restauCount was created to increment the number of Restaurant i inputted,
userRef.push().setValue(users);
The push() method generates a unique key every time a new child is added to the specified Firebase reference
Use
userRef.setValue(users).push();
instead of userRef.setValue(users);
You are using always the same ref
String identifier ="Restaurant" + restauCount;
Firebase userRef = firebaseRef.child("Caloocan");
userRef.setValue(users);
restauCount++;
Check the doc:
Using setValue() in this way overwrites data at the specified location, including any child nodes.
In your case you are overriding the same data for this reason.
You should use the push() method to generate a unique ID every time a new child is added to the specified Firebase reference.
Firebase userRef = firebaseRef.child("Caloocan");
Firebase newRef = userRef.push();
newRef.setValue(users);
//to get the key
String key = newRef.getKey();
you need to update the identifier it stays the same :
int restauCount = 1;
String identifier ="Restaurant" + restauCount;
try something like :
long restauCount = System.currentTimeMillis();
String identifier ="Restaurant" + restauCount;
here each time you send a sendMessage() your identifier got a specific id as the current time in milliseconds + "Restaurant"
if its important to keep int numbers let me know

How do I use the value of a variable AS a variable

Haven't come across this in coding for the android yet. So how do I use the value of one variable as a new variable.
I want to take the value of a variable like "file1.mp3" strip off the extension and then append text to the variable and use it as the variable name like file1_title.txt and file1_desc.txt.
so fName[1] might equal file1.mp3
and then I want to create to new variable
file1_title.txt equals "Song Title One"
file1_desc.txt equals "Description of file One"
both based on the value of fname[1]
fName[2] equals file2.mp3
file2_title.txt equals "Song Title Two"
file2_desc.txt equals "Description of file Two"
both based on of the value fName[2]
etc...
How is this done for the android
I'm not 100% sure I understand the details of your questions, but use a Map. The "key" would be the song title, the value would be the description.
Some followup. Lots of handwaving, no error checking. Assumes that an mp3 File is coming in, and somehow you read the title and description from the tags in the MP3 file. YMMV
// TreeMap will sort by titles which seems reasonable
Map<String, String> songMapTitleToDesc = new TreeMap<String, String>();
MyMP3Reader mmp3r = new MyMP3Reader(File inFile);
String songTitle = mmp3r.getSongTitle();
String songDesc = mmp3r.getSongDesc();
songMapTitleToDesc.put(songTitle, songDesc);
mmp3r.close(); // or whatever
Not sure if this is what you're looking for. It is basic Java string formating.
String attr1 = "song.mp3";
String attr2 = attr1.split(".")[0] + ".txt";
Naturally add the necessary null checks.
==UPDATE==
So if I understand you correctly, you get a file name ("asd.mp3") and need the song title and its description.
String attr1 = "song.mp3";
String songname = "";
String songdesc = "";
String[] splitArray = attr1.split(".");
if(splitArray[0] != null){
String songname = attr1.split(".")[0];
File f = new File(path + songname +".txt");
//I didn't quite understand in what format you get the data,
//especially the description. However, it could be in a map
//where the songname is the key, as suggested above, and here you would write that description to file(f)
}

Categories

Resources