Close Google Map InfoWindows from fragement - java

I am trying to figure out a way to close an open Google Map Marker InfoWindow from another visible fragment by clicking on a button.
An InfoWindow can be closed by simply call marker.HideInfoWinow()
But this assumes you have access to the marker, which I do not have from within the Fragment.
I also read that only one InfoWindow can be open at a time so I was hoping that the map had a method to determine which marker's infowindow was open.
I know to use callback interface to communicate between the map fragment, the activity, and the other fragment.

Related

Google Maps v2: launch custom infowindow without using a marker

My question is regarding the java way of achieving this: Google Maps infoWindow without marker?
Is it possible to launch a custom info window in v2 without using a marker? Which event should I use to detect a long press on the map and how can I launch an InfoWindow?
Here is what I want to achieve.
I need to be able to get the location from the place, so I can add the marker to that position, whenever an icon from the custom view is selected.
Is it possible to launch a custom info window in v2 without using a
marker?
It isn't, but you can create a transparent marker and show the InfoWindow on it.
To make it transparent, use a transparent resource or use marker.setAlpha(0.0f).
Which event should I use to detect a long press on the map?
You can use the method GoogleMap.setOnMapLongClickListener().
How can I launch an InfoWindow?
You have to add a Marker and call showInfoWindow() method on it.

How to make sure that data that has been retrieved from a server is not re-retrieved every time a fragment is called

I am working with fragments and a navigation drawer. I have two fragments and a fragment manager to recycle them when I click on the menu items in the navigation drawer. I am also receiving data from a server in one of the fragments.
However, every time I reinitialize the fragment, the call to the server occurs again. I would like to know if there is any way that I can make sure that the server call only occurs in the beginning and when I click the refresh button.
I would like to know if there is any way that I can make sure that the
server call only occurs in the beginning and when I click the refresh
button.
Yes , when you click on the refresh button use an ClickListener to trigger the call.
If you want the call to occur only when fragment is created you can refer to the fragment life cycle. The better way is to put this call in the onCreate() method.
However if you don't want to make a call each time the fragment is created i recommend you tu use the SharedPreference to save the information that call have already been made.
exemple:
prefs = PreferenceManager.getDefaultSharedPreferences(this);
// The seconde value of method getBoolean incates the default value if constant not found
if (prefs.getBoolean(Constants.CALL_DONE, false)) {
// Make call
prefs.edit().putBoolean(Constants.CALL_DONE, true).apply();
}

Different map markers for every button

I would like to create a main intent(activity) in which someone can choose a track to follow. When a person clicks a button for a certain track, another intent will appear showing the markers along that track on a google map. There will be a "back" button which will bring you to the previous activity.
My question is... can I use a single map and, depending on the button that is clicked, to add specific markers to the map(and erase the previous ones) or highlight that track? How can I transfer a value from one intent to another?(I thought that all the buttons can start the same intent and depending on the value a specific track will be shown).
Any other ideas are welcomed :)
yes you can achieve this using single map.
just call clear() on google map object.
and secondly, on button click pass data using intent.putExtra(string,string)
method and read data by parsing bundle object in map activity
and accordingly add markers to your google map.

Adding a Button to an InfoWindow of a Marker and transfering the Markertitle to a new activity

I'm using a GoogleMaps Activity in Android Studio.
Via OnClick on a Marker an InfoWindow is shown.
I want to add a Button to the InfoWindow that directs to an existing activity with fragment containing more detailed information related to the Marker (A short infotext and a picture of the location)
For this purpose i need to transfer the Markertitle to the Detailactivity to fill in the marker related content.
How may I create this button and transfer the Markername to the Detailactitivy?
According to Info Windows Guidelines,
You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window.
Instead of button, you can use GoogleMap.setOnInfoWindowClickListener(OnInfoWindowClickListener) to start new activity and pass values via Intent.

Help with code layout

I hope I can explain this properly.
I'm making an android app that, when you open it, it connects to a JSON server, pulls down the data (GPS coords) and dynamically creates a "menu" based on what it received (View1). This will consist of a few buttons, which when clicked, will load a MapView (View2) with the coords gotten from the JSON represented as markers on the map.
I start off with setContentView(R.layout.menu) then get the data, onbuttonClick I load setContentView(R.layout.map) and draw the markers. The problem is, I have an onLocationChangedListener that goes through the code to set up the menu initially. When it tries to build the menu when the mapView is open, I get a force close. Unfortunately, this code also updates the user location and the locations of the overlays and re-draws the map.
My question is: Can I do a check on a layout to say something like if (isActive) so that I can perform actions only if the current view is in focus?
OR should I scrap the whole thing and start again with a better layout? (Suggestions welcome)
Summary::: I have 2 views (menu,map). Need access to same data across both. Currently works with setContentView() but gives me a Force Close when actions are performed on inactive view.
If I understand correctly, you are using setContentView(someLayoutId) to change each time what the Activity is displaying. This is not the way android apps usually work. When you retrieve a resource, you need a root element to reference it, that's why you get the exceptions when the View is not "active".
You have several other options to evaluate:
Create a new MapActivity to show the map
Create a TabActivity and add the map as a new tab
Use a ViewSwitcher to decide whether to show the map or not.

Categories

Resources