13

Is it possible to override the source of the tiles that the Android MapView displays?

I have some map imagery tiles in a database, and would like to use the Google maps MapView to look at them.

Also, if this is not possible... does anyone know of a MapView that does allow this? (OpenStreetMap API... MapQuest API... etc)

I am looking for a solution that does not rely on the GPL/LGPL.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Matt
  • 5,461
  • 7
  • 36
  • 43

2 Answers2

5

You can use some of these libraries: osmdroid, mapsforge. Both of them provides interface to some internet map databases and allows to create your own maps provider.

They allows you to have (and handle) your offline cache, dynamic asynchronous maps loading, resampling on zoom, adding overlays and so on, like original MapView does. Another good point of using these libraries is that they are well-designed for in-place substitution of google MapView.

Also you may be interested in Google's Javascript maps api, which also allows to use custom maps source (see this link). This approach can be used with loading map into your WebView. But in this case you still need Google's Maps API key and I'm afraids that you'll be still limited to 25000 usages per day.

== UPDATE ==

Now, Google Maps for Android (that one in Google Play Services) support custom tiles, so there is no more need to use 3rd-party libraries for applying you own tiles (if the usage meets license agreement).

OleGG
  • 8,589
  • 1
  • 28
  • 34
  • Thanks for the response. Unfortunately both osmdroid and mapsforge use the LGPL license, which I was hoping to avoid. I will look into the javascript maps api though. Thanks! – Matt Feb 10 '12 at 20:31
  • Note that if you can use LGPL libraries without opening your code, until your app is not derivative work. Lot of commercial apps uses LGPL libraries (such as Qt framework). – OleGG Feb 15 '12 at 06:52
  • 1
    Also (if we are speaking about non-GPL licenses) there is new JS-based framework Leaflet(http://leaflet.cloudmade.com/). As it was said on webpage, it is well-optimized for using on mobile devices, but I haven't tested it yet. – OleGG Feb 15 '12 at 08:32
  • Strictly speaking, [LGPL](http://www.gnu.org/licenses/lgpl.html) requires that "Combined Works" do various things described in its section 4. Specifically, if you look at section 4d you must either: 4d0 "Convey ... the Corresponding Application Code in a form suitable for ... relink[ing]" or 4d1 "Use a suitable shared library mechanism". 4d1 is not possible with Android since the resulting application is a single DEX, therefore you must open your app to meet 4d0. See the questions raised in http://stackoverflow.com/questions/4916512/using-lgpl-library-in-paid-android-app – bovine Jun 06 '12 at 07:23
  • MapView "GoogleMap" allows you to specify a TileProvider with additional information to render. Then you just turn off the Google tiles. – Brian White Nov 06 '13 at 01:05
  • Actually, this is true for the newer versions of Google Maps API, but my answer was the only way to handle custom tiles in 2012 =) – OleGG Nov 07 '13 at 07:26
3

You can create a TileProvider to return tiles to the Maps API. Then use setMapType to set MAP_TYPE_NONE, and only the tiles you provide will be visible. I know this can be done for a MapFragment, but have not tried it with a MapView.

See the sample code from Google in MapDemo TileOverlayDemo for an example.

Peter B
  • 603
  • 1
  • 8
  • 18