Currently i am working on a weather application, in which i am getting temperature of all countries and i need to show that temperature in info window inside map. only one info window is showing at a time, but i need to show multiple info window, so how to accomplish it ?
googleMap.setInfoWindowAdapter(new InfoWindowAdapter()
{
#Override
public View getInfoWindow(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.infowindow, null);
return v;
}
#Override
public View getInfoContents(Marker arg0) {
return null;
}
});
Marker marker = googleMap.addMarker(new MarkerOptions().position(new LatLng(23.48225949, 83.24252575))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
marker.showInfoWindow();
You could also make the icon for the markers hold the information you need instead of relying on showing that information throught the info window.
That can be accomplished by dynamically creating a bitmap for each marker that includes whatever text you want via canvas.
To avoid doing all tha work yourself you could try using the google maps utility library , see here for an example on how to use a custom marker adapter. It's a bit of extra work, but its a nice library and the clustering is really nice :)
I have a marker and when I open the map it shows the marker. When I click on it it shows the title and a toolbar which includes two buttons on the bottom right of the map which let me launch intents to navigate to the marker or show it in google maps. I would like to have these displayed automatically when the map is opened rather than having the user to click on the marker.
Like this :-) ...
I can't seem to work out how to do this.
I have tried:
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("title");
// adding marker
googleMap.addMarker(marker).showInfoWindow();
googleMap.getUiSettings().setMapToolbarEnabled(true);
But this just shows the marker title and a button on the top right to go to my location not the two toolbar intent buttons on the bottom right.
Like this :-( ...
I'm a bit stuck any ideas?
The overlay that appears when a marker is clicked, is created and destroyed on-the-spot implicitly. You can't manually show that (yet).
If you must have this functionality, you can create an overlay over your map with 2 ImageViews, and call appropriate intents when they're clicked:
// Directions
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?saddr=51.5, 0.125&daddr=51.5, 0.15"));
startActivity(intent);
// Default google map
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?q=loc:51.5, 0.125"));
startActivity(intent);
Note: you need to change the coordinates based on Marker's getPosition() and the user's location.
Now to hide the default overlay, all you need to do is return true in the OnMarkerClickListener. Although you'll lose the ability to show InfoWindows and center camera on the marker, you can imitate that simply enough:
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
return true;
}
});
I added a feature request here:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=7652
Quoting the doc:
In a lite-mode map, the toolbar persists independently of the user's
actions. In a fully-interactive map, the toolbar slides in when the
user taps a marker and slides out again when the marker is no longer
in focus.
Seeems like there is no way to persist the toolbar in your case since its an interactive map. You might want to try using lite-mode if that is a requirement:
https://developers.google.com/maps/documentation/android/lite
Also looking at your code:
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("title");
// adding marker
googleMap.addMarker(marker).showInfoWindow();
googleMap.getUiSettings().setMapToolbarEnabled(true);
The very last line: googleMap.getUiSettings().setMapToolbarEnabled(true); is redundant unless you are explicitly setting it to false beforehand. The doc states:
Sets the preference for whether the Map Toolbar should be enabled or
disabled. If enabled, users will see a bar with various
context-dependent actions, including 'open this map in the Google Maps
app' and 'find directions to the highlighted marker in the Google Maps
app'.
By default, the Map Toolbar is enabled.
The link: https://developer.android.com/reference/com/google/android/gms/maps/UiSettings.html#setMapToolbarEnabled(boolean)
Hope this helps.
if i'm not mistaken you want to show the two buttons that related to the marker on the right botton side of the map and those buttons has some dependency to the marker if i'm true so you just need tu implement a new method like code below and just call this method on create and sure in your marker click listener
#Override
public void markerIntentButtonShow(Marker marker) {
//setvisible(true) to your side buttons or call some Intent
Intent i = new Intent(getActivity(), MarkerViewDetails.class);
i.putExtra("marker_snippet", marker.getSnippet());
startActivity(i);
}
and call the method in your click listener
googleMap
.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
markerIntentButtonShow(marker);
}
});
and in your onCreateView
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("title");
googleMap.addMarker(marker).showInfoWindow();
markerIntentButtonShow(marker);
I had a similar issue..... if you are okay with not letting the user browse in the map and just focus on your marker, you can use lite-mode map....
Quote from documentation
In a lite-mode map, the toolbar persists independently of the user's actions. In a fully-interactive map, the toolbar slides in when the user taps a marker and slides out again when the marker is no longer in focus.
Again from docs
Also by default when a user taps the map, the API starts the Google Maps mobile app. You can override this by using GoogleMap.setOnMapClickListener() to set your own listener. You can also disable click events on the map, by calling setClickable() on the view that contains the MapView or MapFragment.
For the toolbar you have outlined in red, you can disable it using the setMapToolbarEnabled() method in UISettings
From the documentation:
Sets the preference for whether the Map Toolbar should be enabled or
disabled. If enabled, users will see a bar with various
context-dependent actions, including 'open this map in the Google Maps
app' and 'find directions to the highlighted marker in the Google Maps
app'.
Code example to disable the two buttons:
//Disable Map Toolbar:
mMap.getUiSettings().setMapToolbarEnabled(false);
Just in case you were also wondering about the zoom buttons, you can disable them like this:
mMap.getUiSettings().setZoomControlsEnabled(false);
Show a DialogFragment instead of the info window and handle everything in it.
#Override
public boolean onMarkerClick(Marker marker) {
FragmentManager fm = getSupportFragmentManager();
DialogFragment markerWebView = DialogFragment();
mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
markerWebView.show(fm, "fragment_marker");
return true;
}
OR
use the marker clicks to turn an overlay on/off using a facsimile of a Google map button
mMap.setOnMarkerClickListener(this);
mMap.setOnInfoWindowClickListener(this);
#Override
public boolean onMarkerClick(Marker marker) {
//here turn on the overlays for nav turns etc. for this marker.
return false
}
#Override
public void onInfoWindowClick(Marker marker) {
//here turn off the overlays for nav turns etc.
marker.hideInfoWindow();
}
I am currently creating an Android application, that shows the user its current location on Google Maps. I currently have it working so brings up the location, zoomed in.
However, I want the location to be pin-pointed. I have attempted to try and follow the HelloMapView tutorial, but have been having difficulty. How do I modify what the tutorial is saying, to make the Overlay, show the current location?
Also, I have been getting an error, with the getDrawable part of the following:
Drawable drawable = ((Object) this.getResources()).getDrawable(R.drawable.androidmarker);
ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable, this);
Also, whereabouts do I paste this:
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
Thank you.
I want to change my GoogleMaps view between StreetView and Satellite via menubutton.
The code I have used is:
case R.id.item_satellite_view:
mapView.setStreetView(false);
mapView.setSatellite(true);
mapView.invalidate();
return true;
case R.id.item_street_view:
mapView.setSatellite(false);
mapView.setStreetView(true);
mapView.invalidate();
return true;
The problem I am getting is the map only shows blank squares with X in it.
Can anyone please help?
You need to ask for a Google Maps API key. See my own question time ago
Right now, I'm launching the Google Maps application with the following call:
String geoAddress = "maps.google.com/maps?q=";
geoAddress += LatLong[0] + "," + LatLong[1];
Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(geoAddress));
startActivity(i);
Which will open and place a marker at the specified position on the map. I have two questions:
1) How can I place multiple markers of which I have the Longitude/Latitude?
2) How can I start the Maps application to other modes (terrain/satellite/etc.)?
Thanks!
you can add multiple links on the map by using overlays,and u can see the GoogleMapview example in http://developer.android.com/resources/tutorials/views/hello-mapview.html.
here you can understand use of overlays.
Read the following links and download the code the link(For Further reference)
https://github.com/jgilfelt/android-mapviewballoons
https://github.com/jgilfelt/android-mapviewballoons#readme
2.To change the views use following functions,
mapView.setSatellite(true);
mapView.setStreetView(true);
For further reference
http://mobiforge.com/developing/story/using-google-maps-android