How do I pass custom data to Google Maps v2 InfoWindowAdapter? - android

I am trying to take advantage of an InfoWindowAdapter to provide custom content for the InfoView. I'm pulling down a JSONArray from my web service and adding the Markers but I'm not seeing how to pass the detail to the call back via a Marker.
#Override
public View getInfoWindow(Marker marker)
In the Javascript API I was able to just set arbitrary marker info. I want to be able to pass info that can be used as conditionals for the custom content, example a marker.status string. So something other than title etc. The view will need a number of custom fields I need to pass in.

perhaps try adding your info or object to the marker as explained here:
http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html
Edit: I also made a post that continues the previous to use the InfoWindowAdapter.
Check it out here!

Related

How to keep state for polygons?

I was reading the documentation for polygons and polylines
What is not clear to me is how could I keep a state associated with a polygon?
E.g. if I want to do an action on click that depends on whether the polygon was already clicked on or not how could I know that?
Could I use e.g. tag to add arbitrary info including if the polygon is in click/state?
you can use setTag() with custom object which include click state and other data like
CustomDefinedObject data = new CustomDefinedObject ();// your defined object
data.isClicked=true
data.otherProperty=false
polyline.setTag(data);
and to retrieve info
CustomDefinedObject retrievedData = (CustomDefinedObject)polyline.getTag(data);

Would it possible to implement a button to the approach I'm taking to display information in a Google Maps marker in Android?

I'm creating a small app that will help a user find a sports club. I'm currently creating a club coordinate variable in the MapsActivity.java file like so:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng lansdowneRFC = new LatLng(53.3334103,-6.2201649);
// Adds location to the map (includes a small bit of info about the club)
mMap.addMarker(new MarkerOptions().position(lansdowneRFC).title("Lansdowne RFC").snippet("Aviva Stadium, 62 Lansdowne Rd,"));
}
This produces the following result
I'm trying to add a button to the information box that will bring the user to another activity (The activity will be a sign up form so they can join the club). Considering the approach I'm using is it possible to implement a button or will I have to approach it in another way? I've seen ideas like a custom popup window be suggested for this type of thing but how I implement that into a google maps marker instead of a button is where I'm hitting a brick wall. Any suggestions
You can set your own implementation of InfoWindowAdapter to your GoogleMap object with a call to setInfoWindowAdapter().
And in the adapter you can override getInfoContents() to return whatever view you want.
But the down side is the view that is shown is not a live view, it's an image of the view you created, and you can handle the click on it using a OnInfoWindowClickListener that you set on the GoogleMap object with setOnInfoWindowClickListener().
But that handles the click on the whole window, not just the button.
Another option is to know where your marker is at the screen and show a popup manually above it that has nothing to do with the map, but I would not recommend that approach, with Android's different device sizes and all, that could quickly get very ugly.

How to implement first person view in android google map?

In my android application i want to implement first person view. Please check following URL for first person View -
Google First Person View
I found one link which redirects to first person view please check -
Google Maps Navigation - Using Google Navigation in Android Application
But in it we don't have control over navigation view or first person view. It redirects to google's default first person view. I want to implement it manually. Means in which we can pass latitude and longitude dynamically(from Server)
Is there any way to implement first person view Pro-grammatically, in which we have command over view ?
Thanks in advance!
Don't know exactly, how to achieve that view, but you can do one thing, that is whatever orientation's value you are getting from your server or any gps device , pass it into bearing() method of CameraPosition and set tilt also, like following -
CameraPosition cameraPos = new CameraPosition.Builder().target(latlng)
.zoom(zoomvalue).bearing(orientation).tilt(tiltvalue).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos), null);
by doing this your map will be rotate according to value of orientation. and if you pass value of orientation into rotation(orientation) method of marker then your marker will rotate according to value.
Hope it'll help you.

Android Google Maps API: Hide Marker Snippet

I am using the Google Maps API v2 and 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 don't actually want the reference ID to be visible to the user. I added the reference ID as a snippet and use marker.getSnippet() to get the reference ID to pass to the new activity. Is there a way to hide the snippet so the user doesn't see it?
Customize the info window contents via an InfoWindowAdapter, attached it to your GoogleMap via setInfoWindowAdapter(). Implement onInfoContents() on the adapter to return something that does not contain your snippet.
I've been looking for the same thing and found something interesting myself.
The trick might seem so dumb but it worked perfect.
After getting the value from the Snippet in onMarkerClick(Marker m) I'm setting it back to null :D
Here is the code:
#Override
public boolean onMarkerClick(Marker marker) {
locationMarker = marker;
Intent intent = new Intent(getApplicationContext(),MarkerInfoView.class);
String uid = marker.getSnippet();
marker.setSnippet("");
intent.putExtra(UID,uid);
startActivity(intent);
return false;
}
So, on onClick() it shows the title and opens another activity and shows the related other information of the user there.
Give me crazy thumbzzup if it works for you ;)
Let me know if anyone need other coding help on tracking user and marker click operations.I'll try yo help as much as possible.
Good Luck (y)
Screenshot here:

List & Map Marker clicks

I've got an Activity that holds a ListFragment on the left and a SupportMapFragment on the right.
List and Map are both backed by the same data. The visual representation of the data on the Map are Markers.
I want to be able to perform a click on either a list item or a Marker and get the corresponding item in the other visual representation.
Restrictions of the framework and my data are:
The Marker class is final and the Marker's id does not have a modificator. This is why I can't use the easiest possible way.
"It's important to not hold on to objects (e.g. Marker) beyond the
view's life. Otherwise it will cause a memory leak as the view cannot
be released." (see SupportMapFragment)
Titles of Markers can occur multiple times. This is why the expensive String comparison is not a way I can go.
Does anyone have a working solution for this issue or can provide a nudge in the right direction?
If you want to be able to register to clicks on a Marker, you'll need to override the InfoWindowAdapter.
You can provide unique information to the title and snippet of a Marker and implement the interface's methods in this style:
#Override
public View getInfoWindow(Marker marker) {
// do nothing here in order to obtain the original info window border.
return null;
}
#Override
public View getInfoContents(Marker marker) {
// Create your own view here. Obtain the unique information stored
// in title / snippet of the current marker.
return createdView;
}
Now you can set the OnInfoWindowClickListener and work with the unique information stored there.
Here's another option. The latest APIs provide an OnMarkerClickListener interface.
https://developers.google.com/maps/documentation/android/marker#marker_click_events

Categories

Resources