'Android Google Maps: Hiding labels and showing markers
I want to develop an Android application where I present users with a map with some markers. On the basis of a question they select a marker which is then evaluated as correct or wrong. Now the problems:
This can be implemented with Google Maps Android API v2:
- But problem is that I am not able to hide country, state or continent names. That takes away the purpose of the game. Can I blur out the names? Can I prevent zoom?
Using WebViews and Google Maps in WebView:
- Problem is that markers cannot be made clickable for this. How can I do this. Plus where is javascript coding done? Could I have tutorials for this?
Using offline maps.
Is that a possibility. Can I put markers on it, and know where user clicked?
The application "Geography Learning Game" does it nicely, and it also has Google written at the bottom, so they are using Google maps only. http://goo.gl/obE1fB
Answering any of the above will solve my problem. Please reply with code.
Solution 1:[1]
I found an answer, and would love to help anyone who comes across this while browsing.
Country, continent etc names can't be hidden using Google Maps, so OpenStreetMaps overlay layer is to be used over Google Maps.
So rest of the code remains same, just add an overlay. This selectively hides what has to be hidden.
Refer to https://code.google.com/p/osmdroid/ for the procedure to implement this.
Hope it helps!
Solution 2:[2]
You can customize your map by applying map style using GoogleMap.setMapStyle(MapStyleOptions) (method reference). You can create map style here (just move 'labels' progress bar to customize map labels). Copy map style json and create raw resource with its content.
Your onMapReady will look like this:
override fun onMapReady(googleMap: GoogleMap) {
try {
googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(context, R.raw.map_without_labels_style)
)
} catch (e: Resources.NotFoundException) {
// log it
}
}
More information could be found here
Solution 3:[3]
Your best option might be to use a different map type. I assume you're using the default MAP_TYPE_NORMAL. This can be changed after the map has been created (i.e. in the onMapReady method by using the mMap.setMapType(...) method). Here are some possibilities:
MAP_TYPE_NORMAL + Custom Map Style
You can easily create your own map styles by using the Styling Wizard. It allows you to create a style that excludes labels entirely (among other things). Once you've created a style you like, you can copy the JSON code generated by that website and add it to the project file res/raw/style_json.json. It can then be applied like this:
mMap.setMapType( GoogleMap.MAP_TYPE_NORMAL );
try
{
boolean success = mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
getContext(), R.raw.style_json ) );
if( !success )
{
Log.e( TAG, "Style parsing failed." );
}
}
catch( Resources.NotFoundException e )
{
Log.e( TAG, "Can't find style. Error: ", e );
}
MAP_TYPE_NONE + Custom Map Tiles
You could add a TileOverlay of non-Google map tiles (like those provided by OpenStreetMap). You would have to find a set that does not include labels within the tiles themselves.
Map Types Without Labels
MAP_TYPE_SATELLITE and MAP_TYPE_NONE don't include labels. However, it sounds like MAP_TYPE_NONE would not be useful for your application by itself.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ankit Aggarwal |
| Solution 2 | Valeriy Posvistak |
| Solution 3 | Matt Nemmer |
