Android Google Maps API: Hide Marker Snippet - android

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:

Related

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.

Custom popup activity in android instead of dialogue

I am making an app that uses maps api, and I want to create a custom popup activity when the user creates a marker (not the generic yes/no dialogue). What I want to do is:
when a user longclicks on map it opens a new activity instead of dialogue
this activity displays lat and lang, has a field to enter text, and yes/no buttons
if a user clicks yes the marker is pinned if no it is not
when a user clicks on the created marker it displays lat,lng and the entered text
My current code:
//Add marker on long click
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng arg0) {
Intent intent = new Intent(getActivity(), CreateRestautantActivity.class);
startActivity(intent);
marker = mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker))
.position(
new LatLng(arg0.latitude,
arg0.longitude))
.visible(true));
}
});
Any help is appreciated :)
Ok, maybe I didn't got all the details, but in such case I'd do the following:
1. Use OnMapLongClickListener. Then in onMapLongClick() you can do whatever you want. You have LatLng object with latitude and longitude - you can put them in a Bundle or pass them in other way to new Activity.
You can refer this post for example.
Create a Marker and store it as a field in your Activity.
2. It's easy, I suppose, to make xml for new Activity and use it at setContentView(). Take your arguments passed in previous step and put them in lat and lng fields. Put OnClickListener on your buttons.
3. You can start your new Activity with StartActivityForResult method and handle results from your new Activity on return.
There is also a lot of information about that on stackoverflow. For example this.
Then, in onActivityResult() you can make some actions to your Marker (remove it, for example).
4. Use OnMarkerClickListener - and in onMarkerClick(Marker marker) from that Marker you can call getPosition() - and take lat and lng from it.
If you need more details, let me know ;)
You should use a DialogFragment. This allows you to customize the appearance and functionality of a dialog.
Android blog post on how to use them: http://android-developers.blogspot.com/2012/05/using-dialogfragments.html
Reference: https://developer.android.com/reference/android/app/DialogFragment.html
Several other tutorials/examples: https://www.google.com/search?q=dialogfragment

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.

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

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

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!

Categories

Resources