Here Map Premium plan Map.InfoBubbleAdapter() ,hideInfoBubble ,getInfoBubbleContents and isInfoBubbleVisible missing? - android

I am trying to show the custom layout when user clicks on the marker object.
The basic pack code works properly .
However when i shifted to premium pack it does not have
Map.InfoBubbleAdapter(),hideInfoBubble,getInfoBubbleContents and isInfoBubbleVisible.
I am not even able to open the infoBubble when user click on marker too.
This is the code for custom view in basic pack i used.
hereMap.get(new Map.InfoBubbleAdapter() {
#Override
public View getInfoBubbleContents(MapMarker mapMarker2) {
return null;
}
#Override
public View getInfoBubble(MapMarker mapMarker2) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_marker_infowindow, null);
TextView infoWindowText = view.findViewById(R.id.infoMessage);
infoWindowText.setText(mapMarker2.getTitle());
return view;
}
});
and this is the code that i was using on click of marker
#Override
public boolean onMapObjectsSelected(List<ViewObject> objects) {
for (ViewObject object : objects) {
if (object.getBaseType() == ViewObject.Type.USER_OBJECT && ((MapObject) object).getType() == MapObject.Type.MARKER) {
MapMarker mapMarker = (MapMarker) object;
System.out.println("Title is................." + mapMarker.getTitle());
if (!mapMarker.isInfoBubbleVisible()) {
mapMarker.getInfoBubbleContents();
} else {
mapMarker.hideInfoBubble();
}
return true;
}
}
How can i show the custom info bubble when user click on the marker?

You should use sticky map overlays instead:
https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/mapping/MapOverlay.html
Then add your MapOverlay implementation to the Map via Map.addMapOverlay:
https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/mapping/Map.html#addMapOverlay-com.here.android.mpa.mapping.MapOverlay-
The idea behind is, that you can use a normal Views (very flexible, your own design, etc.) and stick it to a position on the map (and the map will keep it in place then). This gives you full flexibility on logic and design.

Related

Here Map Premium plan issue in setting MapOverlay custom view on top of marker

I want to add a custom layout Infowindow on top of the marker. Android Here map Basic pack was having the following features Map.InfoBubbleAdapter() ,hideInfoBubble ,getInfoBubbleContents and isInfoBubbleVisible which are now missing in the Premium pack .
As suggested in Here Map Premium plan Map.InfoBubbleAdapter() ,hideInfoBubble ,getInfoBubbleContents and isInfoBubbleVisible missing?
This are the list of issues.
I have implemented MapOverlay which seems to give custom layout
but its not aligned to the marker.
The infoWindow is getting visible when i am trying to zoom in,even when i have not tuned on the visibility of layout.
The position of infoWindow is not on the geoCordinate that were set to mapOverlay.
I have 20 different marker and i want to show the custom info window when user taps on any marker and turn off the previous marker .
I tried the code below but its not working and there seems no documentation on implementation.
#Override
public boolean onMapObjectsSelected(List<ViewObject> objects) {
for (ViewObject object : objects) {
if (object.getBaseType() == ViewObject.Type.USER_OBJECT && ((MapObject) object).getType() == MapObject.Type.MARKER) {
MapMarker mapMarker = (MapMarker) object;
if(!isMapMarkerViewVisible()){
setInfoWindow(mapMarker);
}else{
removeInfoWindow();
}
return true;
}
}
return false;
}
#Override
public boolean onTapEvent(PointF pointF) {
for (MapObject mapObject : mapObjects) {
if (mapObject.getType() == MapObject.Type.MARKER) {
removeInfoWindow();
}
}
return super.onTapEvent(pointF);
}
private void setInfoWindow(MapMarker mMark) {
infoWindowText.setText(mMark.getTitle());
infoWindowText.setTag(mMark.getTitle());
mapOverlay = new MapOverlay(infoWindowView, mMark.getCoordinate());
hereMap.addMapOverlay(mapOverlay);
}
private boolean isMapMarkerViewVisible(){
return infoWindowView.getVisibility() == View.VISIBLE;
}
private void removeInfoWindow() {
if(infoWindowView!=null) {
if (infoWindowView.getVisibility() == View.VISIBLE) {
infoWindowView.setVisibility(View.INVISIBLE);
}
}
}
The above code behaves strangely .
When i try to zoom in and out the info window strangely appears on the map .Even when i have not set the visibility.
The Above link have the code that was working but its not supporting now.
Different from MapMarkers, the MapLabeledMarkers avoid overlapping with other user-defined labeled icons as well as built-in icons and texts on the map. It provides the possibility of using built-in POI icons by specifying a IconCategory or using an Image. One can specify multilingual texts to the icon. Depending on the current language and secondary language of Map, different language of text can be displayed.
MapLabeledMarker(GeoCoordinate loc)
Creates a MapLabeledMarker at a specific GeoCoordinate with a default POI icon.
MapLabeledMarker(GeoCoordinate loc, Image icon)
Creates a MapLabeledMarker at a specific GeoCoordinate with the specified Image.
For more detailed reference please refer & upgrade to newest version of SDK : https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/mapping/MapLabeledMarker.html

MapQuest(Android SDK) : Drop a pin on map and automatically open a window

I'm using MapQuest Android SDK in my application.
I have scenario where I drop a pin on map and I want to automatically open a the window for the pin.
I'm using MapboxMap.InfoWindowAdapter and method getInfoWindow( Marker marker) . My question here how to automatically open window as soon as i drop the pin.
I want to open window automatically after dropping the pin?
Here is my code:
#Override
public void onResume() {
super.onResume();
//This is where I pass my poi from poiSearchListview Fragment to my Map Fragment through Activity. So On onResume() if will call this method.
if (null != getActivity.getPoiFields()) {
fromSearchFrag = true;
addPoiMarker(getActivity.getPoiFields());
}
}
This is my OnCreateView() method:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.map, container, false);
mMapView.getMapAsync(new OnMapReadyCallback() {
mPoiFields.clear();
if (null != getActivity.getPoiFields()) {
fromSearch = true;
addPoiMarker(getActivity.getPoiFields());
}
mMapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
#Nullable
#Override
public View getInfoWindow(#NonNull Marker marker) {
View customView = null;
**//Here I have my own window my own images, texts and buttons.**
return custom view;
}
});
}
});
This is my method for adding POIMarker on Map at OnResume()
public void addPoiMarker(Fields poiFields) {
final String name = poiFields.getName();
poiAddress = poiFields.getAddress() + ", " + poiFields.getCity() + ", " + poiFields.getState();
Drawable iconDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.pointofinterest);
Icon icon = IconFactory.getInstance(getActivity()).fromDrawable(iconDrawable);
if (mMapboxMap != null) {
mMapboxMap.removeAnnotations(); // TO remove all the markers before dropping the Address marker from search.
markerOptions = new MarkerOptions().icon(icon).position(
new LatLng(poiFields.getLat(), poiFields.getLng())).title(name);
mSearchResultMarker = mMapboxMap.addMarker(markerOptions);
mPoiFields.put(mSearchResultMarker, poiFields);
// mMapboxMap.selectMarker(mSearchResultMarker);
// **IF I use selectMarker it shows just the address on the window and
not my custom window.
I want to show my custom info window here as selectMarker doesn't clear my issue, what to do ?**.
}
zoomToPin(poiFields.getLat(), poiFields.getLng());
}
Try using mapboxMap.selectMarker() passing in the marker you want to select.
EDIT: I modified the demo app example CustomInfoWindowActivity to produce both scenarios you have mentioned in your comment below. I simulate scenario 1 by simply clicking the map (not animating the marker dropping), this calls mapboxMap.selectMarker() and displays the custom info window as expected. Scenario 2 is working as expected too when clicking the marker icon.
if I'm still not understanding the issue, please provide additional code and pictures/videos/gifs of the issue.
Have you tried invoking the showInfoWindow() method on the Marker?

Put layout above google Map marker Android

I have a custom "InfoWindow" for a marker, which has buttons, but for default user can't click over the buttons or slide on lists of that layout because that info window is like an image.
Note: the solution in https://stackoverflow.com/a/15040761/2183804 doesn't apply to my problem because different markers has different info Windows (I already tried modifying that answer without success).
So, to solve my problem, I though on putting a layout above the marker when the user clicks over the marker. How can I achieve to put the layout above the marker?
In this example, I have a list with clickable items in the layout
A solution can be find on this link: https://stackoverflow.com/a/31995000/3957303
The basic idea is to use a PopupWindow to show the layout on the screen, and then play with its location to potition it over the marker with the updatePopup method described in the answer. And every time the camera changes (listening to the CameraChangeListener), you call the updatePopup method.
I have achieved this by adding a custom info window adapter. And then set it to my map . And in getInfoWindow() of adapter ,you can write all the click listeners to your views.Here is the code .
private class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private View view;
public CustomInfoWindowAdapter() {
view = getLayoutInflater().inflate(R.layout.custom_info_window, null);
}
#Override
public View getInfoContents(Marker marker) {
if (marker != null
&& marker.isInfoWindowShown()) {
marker.hideInfoWindow();
marker.showInfoWindow();
}
return null;
}
#Override
public View getInfoWindow(final Marker marker) {
final ImageView image = ((ImageView) view.findViewById(R.id.badge));
final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}
return view;
}
}
And set it to map by this
private GoogleMap mMap;
mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
Hope it helps. Happy coding...

Changing infoWindow view depending on click listener

I am trying to implement a Google Map marker with infoWindow that if someone clicks on this infoWindow, it plays a song and if clicks again, it stops. To visualize this, I write a custom infoWindow layout. There is, in infoWindow, you can see user and track info with a button. This button shows play icon if the track does not begin to play yet, and if it pressed (press on infoWindow, not the button), I hope it changes its icon from "play" to "stop". However, I cannot change my custom infoWindow's view depending on infoWindowClickListener activity. I tried to change infoWindowAdapter especially but I do not want to change view of all other infoWindows and also I want to see the change immediately. In this way, the infoWindow refreshes its view after I click on the marker again. In other words, it does not change the view simultaneously with my click action.
Here you can see what I am talking about. Stop status on left, play status on right:
Here is my futile effort for adapter:
public class OrangeInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
Context context;
ImageButton playButton;
boolean onPlay;
public OrangeInfoWindowAdapter(Context context, boolean onPlay) {
this.context = context;
this.onPlay = onPlay;
}
#Override
public View getInfoWindow(Marker arg0) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.orange_infowindow, null);
v.setMinimumWidth(280);
v.setMinimumHeight(120);
TextView tvUsername = (TextView) v.findViewById(R.id.tv_username);
TextView tvTrack = (TextView) v.findViewById(R.id.tv_track);
int index = arg0.getTitle().indexOf("*");
try {
tvUsername.setText(arg0.getTitle().substring(0, index - 1) + "\n" + arg0.getTitle().substring(index + 2));
} catch (StringIndexOutOfBoundsException e) {
}
tvUsername.setTextSize(10);
tvUsername.setTextColor(Color.rgb(70, 70, 70));
index = arg0.getSnippet().indexOf("*");
try {
tvTrack.setText(arg0.getSnippet().substring(0, index - 1) + "\n" + arg0.getSnippet().substring(index + 2));
} catch (StringIndexOutOfBoundsException e) {
}
tvTrack.setTextSize(10);
tvTrack.setTextColor(Color.rgb(230, 92, 1));
playButton = (ImageButton) v.findViewById(R.id.playButton);
if (onPlay)
onPlay();
return v;
}
public void onPlay() {
playButton.setBackgroundResource(R.drawable.info_stop_button);
}
public void onStop() {
playButton.setBackgroundResource(R.drawable.info_play_button);
}
#Override
public View getInfoContents(Marker arg0) {
return null;
}
}
And this is my onInfoWindowClick():
#Override
public void onInfoWindowClick(Marker marker) {
if (!infoWindowPlayerActive) {
int index = findMarkerIndex(marker);
OrangeInfoWindowAdapter infoWindowAdapter2 = new OrangeInfoWindowAdapter(getActivity().getApplicationContext(), true);
googleMap.setInfoWindowAdapter(infoWindowAdapter2);
new InfoWindowPlayerTask(mainActivity).execute(activities.get(index).getTrackId());
infoWindowPlayerActive = true;
}
else {
// same thing...
infoWindowPlayerActive = false;
}
}
If you want more information to understand the problem clearly, please ask me.
The GoogleMap API v.2 does not support any interaction on InfoWindow, besides opening and closing it.
However, there is an amazing hack implemented in this answer, on how you should create an interactive View inside your InfoWindow. Keep in mind that the same technique applies for Fragments too.
From the official documentation:
Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
I found a sloppy but working solution:
#Override
public void onInfoWindowClick(Marker marker) {
if (!infoWindowPlayerActive) {
googleMap.setInfoWindowAdapter(infoWindowAdapterOnPlay);
marker.showInfoWindow();
newClickedInfoWindowIndex = findMarkerIndex(marker);
if (lastClickedInfoWindowIndex != newClickedInfoWindowIndex) {
new InfoWindowPlayerTask(mainActivity).execute(activities.get(newClickedInfoWindowIndex).getTrackId());
}
else {
mainActivity.getPlayerManager().clickPlayPause();
}
lastClickedInfoWindowIndex = newClickedInfoWindowIndex;
infoWindowPlayerActive = true;
}
else {
googleMap.setInfoWindowAdapter(infoWindowAdapter);
marker.showInfoWindow();
mainActivity.getPlayerManager().clickPlayPause();
infoWindowPlayerActive = false;
}
}
public int findMarkerIndex(Marker marker) {
for (int i = 0; i < markers.size(); i++) {
if (marker.getPosition().equals(markers.get(i).getPosition())) {
return i;
}
}
return -1;
}
Of course, assume that infoWindowPlayerActive, lastClickedInfoWindowIndex, newClickedInfoWindowIndex are defined in the class above.

How to customize appearence of android google maps api v2 info window?

In my android app, I have a info window for a marker I place on the map. I want to do these things:
Make the default marker bigger (its too small now)
When the info window shows up, the text in it is making the width too long. Is there a way I can set a maximum width on it?
How can I increase the font size for the title and text?
Can anyone show me how to do this?
Thanks.
Maybe a little late, but you need to create a new custom adapter you can take a look in here: How to change Google Maps marker window Info
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(com.google.android.gms.maps.model.Marker arg0) {
return null;
}
#Override
public View getInfoContents(com.google.android.gms.maps.model.Marker marker) {
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View mView = null;
//using the id, you can store multiple types of markers on List's and change the layout
if (marker.getId().equals(end.getId())) {
mView = inflater.inflate(R.layout.custom_info_window, (ViewGroup) findViewById(R.id.map), false);
((TextView) mView.findViewById(R.id.txtTitle)).setText(marker.getTitle());
}else{
mView = inflater.inflate(R.layout.normal_info_window, (ViewGroup) findViewById(R.id.map), false);
((TextView) mView.findViewById(R.id.txtTitle)).setText(marker.getTitle());
((TextView) mView.findViewById(R.id.txtDescription)).setText(marker.getSnippet());
}
return mView;
}
});
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
//do whatever you need
}
});
In te custom view you can modify the size of the font, and other things, for the first point the marker icon can be modified on the MarkerOptions.setIcon, where you can use one from your assets.
1: When you add the Marker to the map, you can set the icon in the MarkerOptions. Make your own icon and use that.
2 & 3: Set an onMarkerClickListener on your GoogleMap. In the callback, you can create and show your own info window view on the map (just make sure you return false from the onMarkerClick() callback)

Categories

Resources