Make Map Fragment Clickable - android

I have an map fragment in my android application. What I want to do is make it clickable so that if someone clicks anywhere on the fragment I can start a new activity. I tried doing some research but all I'm coming up with is how to make map markers clickable or not clickable. My map fragment only takes up a small portion of my activity and shows only one map marker.

Try this:
map.setOnMapClickListener(new OnMapClickListener() {
#Override
public void onMapClick(LatLng point) {
startActivity(new Intent(yourActivity, nextActivity.class));
}
});

i think you do it implementing on touch listener on map fragment view it will work for me, if click on map fragment u can open map full view in another activity.
may be this will be help u

Related

Reinitialising Fragment when closing activity

I have an Activity with a fragment, this fragment has a map in it and some markers.
I run a service in the background that changes the position of the markers.
Each Marker has a boolean "isDrawn" and whenever the boolean is set to false the map is updated by adding drawing the marker ( I use LiveData to observe the markers)
Whenever I close the Activity that contains the fragment I call onDestroyView, which sets isDrawn of every marker to false. That way when I open the Activity again, the markers get drawn one more time. All of this works fine.
The problem is this: in the Fragment I can tap on the markers, which opens a view that has a button which opens another Activity, when I close this Activity (With BackButton) and if a marker changed its position (through the service) when I was in said Activity, I find that there are two of the same marker on the map.
Any idea what I could do? Should I remove the fragment and create it again when I close the activity? is that possible? if so how should I proceed?
Here you can try 2 options
Try creating a static variable and and store some flag values.
check whether the Fragment is visible with the help of isVisible() or getUserVisibleHint()
You must be using this method to add a marker to the map.
public final Marker addMarker (MarkerOptions options);
take one variable of type Marker and store the reference of it which is returned by addMarker (MarkerOptions options);
like
if(marker!=null){
marker.remove(); //will clear the previous one, it might be null at first.
}
marker=addMarker(yourOptions);//will add the latest one

Draw over single application

I have opened "Google Map" Application from my App.
What I want is I want to add my app button for navigating to my app, over only google map not on other apps.
Using this link ,I have added overlayservice to my app but it will overdraw over every other application on device window.
I only want to draw over google map app Like this.
This started off as a comment, and then morphed into something of an answer. One option would be to draw a custom marker on your Google Map for the taxi icon. Whenever there is a zoom, drag, etc., you might have to do a re-render to get it in the same place again. I can verify that it is possible to capture click events on a custom marker in Android. Here is what your setup might look like:
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setOnMarkerClickListener(this);
mMap.setOnCameraMoveListener(this);
// ...
}
Then, override the marker click listener:
#Override
public void onCameraMove() {
// remove the old marker, and redraw it again on the left of the screen
}
You also probably would want to capture click events on your custom marker:
#Override
public boolean onMarkerClick(final Marker marker) {
// ...
}
The above onMarkerClick() method receives a reference to the marker which was clicked. You may keep an activity-scoped marker, and then check if it matches what was clicked to decide whether or not your custom marker were clicked.

Android Google maps how to zoom to a specific area

I have 2 different activities: On the first one i have my map and I am doing something else on the second one. I have a button on the second activity and I want that button to display a specific area on the map when it's clicked. But my code stops the app when I click the button. The weird thing is that if I remove the 2 lines of code above cameraUpdate, when the button is clicked, it just takes me to the other acitivity displaying the map, but I want it to zoom on a specific area, which it doesn't.
public void show_map(View x){
Intent intent = new Intent(getApplicationContext(), THEMAP.class);
startActivity(intent);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_AMERICA,13);
gMap.animateCamera(update);
}
You should be placing your code to manipulate the map in the Activity that actually contains the map, not in the launching Activity. You'd need to post more of your code for me to be sure, but try moving
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_AMERICA,13);
gMap.animateCamera(update);
into your onCreate() in THEMAP (not your actual class name I hope.

Android: Google Maps API v2 rendering issue with markers and camera animation

EDIT
I've found a better STR:
Make sure to set "Do not keep activities" in Developer options in Settings.
Open the app with a SupportMapFragment as a child fragment of another fragment.
Switch to another app
Open your app again
Notice you can't interact with the map and no animations work.
Open another screen within the app
Notice there's a single frame or so of the map with the markers drawn on screen.
I have an issue with Google Maps API v2.
I am animating the camera to zoom to a set of custom marker bitmaps rendered on a MapFragment.
On selecting one of these marker tooltips I open a geo: intent (for the Google Maps app etc.)
When the user presses back it reopens my activity with the fragment back stack rebuilt.
My issue is that it doesn't render camera animations or the markers on coming back, though there is a brief display of those markers when the user presses back to go to the previous fragment.
The GoogleMap instance has the markers, but it doesn't render them - I'm guessing because the MapFragment/MapView thinks it doesn't need to be rendered.
How do I force a render of the MapView? Failing that, how do I get the MapView to recognise that the model has changed?
The issue was to do with the way I was handling my child fragments.
Every time the parent fragment would call onCreate the children fragments would get recreated.
I did the following to handle my child fragments, but there may be a better way:
private static final String TAG_FRAGMENT_MAP = "TagFragmentMap";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
if (savedInstanceState == null) {
// create the fragments for the first time
ft.add(R.id.view_flip, new SupportMapFragment(), TAG_FRAGMENT_MAP);
ft.commit();
}
}
// ...
public void onViewStateRestored(Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
mMapFragment = (SupportMapFragment)findFragmentByTag(TAG_FRAGMENT_MAP);
}

Android OnInfoWindowClickListener() never called

I'm creating an application with new Google Maps API V2 and I have to intercept the click on InfoWindow, showed when a Marker is clicked.
Reading the documentation I assumed that I do that to listen to InfoWindows clicks :
mGoogleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
Log.d("", marker.getTitle());
}
});
But unfortunatly the method is never called.
If I try to listen to marker click and use setOnMarkerClickListener instead of OnInfoWindowClickListener , this works fine.
Hope to find some help, thanks in advance
The OnInfoWindowClickListener gets called when you actually click on the Marker title popup and not the marker.
The above just works fine.

Categories

Resources