java - How to find the marker postion by its title? -
I have a list where a user types the name of a place and chooses it. Clicks the username and shows the location of an infowindow name.
I have already made markers. I am able to get the title of the marker clicked by the user. How do I get the marker status from the title of the marker?
My
// My list has been removed from the XML file string [] [countries] = getResources (). GetStringArray (R.array.list_of_countries); ArrayAdapter adapter = new array adapter (this, android.R.layout.simple_list_item_1, country); Actv = (AutoCompleteTextView) findViewById (R.id.autoCompleteTextView1); Actv.setAdapter (adapter); actv.setOnItemClickListener (see New AdapterView.OnItemClickListener () {@ Override public void onItemClick (AdapterView & lt;? & gt; parents, see, see int position, long id) {CharSequence country = ((TextView)) .getText (); toast .makeText (getBaseContext (), country, Toast.LENGTH_SHORT) .show () ;. // here if I titled "EF" title, for example marker //, I know how to do it LatLng = 23,82}});
Here are my markers: ..
googleMap.addMarker (New MarkerOptions () Condition (new LatLng (23,81)) title ( "Atal Bihari")); GoogleMap.addMarker (New Marker Option.) Status (New wave long (2481)) Title ("CD"); GoogleMap.addMarker (New Marker Option.) Status (New wave long (2382)) Title ("EF"));
0x5f3759df shows in his answer, you have to loop through the markers And search for them. The problem is that there is no constructor for the marker class, so you do not make them and then add them to the map, as soon as you add them to the map. The other problem is that there is no way to get the marker from the map after you add them. If you refer to the addMarker method, then it returns to the marker as it says to the map, then the trick is to store a reference for what is given by the addMarker method. So what you need to do is something like this So as you add the map to add them into your ArrayList Then something like this You can then use a loop to find the marker with the title, or any other attribute.
Arreelist & lt; Marker & gt; Mapmarks = new array list & lt; Marker & gt; ();
mapMarkers .add (GoogleMap.addMarker (New Marker Option.) Status (New wave long (2381)) Title ("AB")));
marker found = null; For (Marker M: Mapmarker) {If found (whatever) = M; } If (found! = Null) doSomething ();
Comments
Post a Comment