Update (August 5, 2013)
This widget has been superceded by TileView. All future commits will be to TileView. MapView will be eventually discontinued entirely as TileView supercedes it.
Update (April 20, 2013):
Updating to 1.0.2, fixing a couple bugs, adding support for custom Bitmap decoders, improved intersection calculation (thanks to frankowskid), and some standardization. Also added the source for a sample app and a working .apk
Changes:
Update (March 28, 2013):
Updating to 1.0.1, fixing several bugs, reinstituting undocumented or previously removed features, and adding some experimental stuff.
Fixes:
Enhancements:
Known issues:
Note that the documentation has not been updated, nor has the jar - will get to those as soon as I get some time
Update (March 8, 2013):
While this component is still in beta, the version now available should behave predictably.
This commit entails a complete rewrite to more closely adhere to Android framework conventions, especially as regards layout mechanics. The changes were more significant than even a major version update would justify, and in practice this version should be considered an entirely new component. Since we're still debugging I'm not bothering to deprecate methods or even make any attempt at backwards compatability; the previous version in it's entirely should be considered deprecated, and replaced with this release.
The documentation has been updated as well.
An quick-n-dirty, undated, unversioned and incomplete changelog:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />. Testing for permission is on the todo list - right now you'll just get a runtime failure.
If you test this on a device, please let me know the results - in the case of either success or failure. I've personally run it on several devices running several different versions of the OS, but would be very interested in results from the wild. I'll be working on putting up a jar and a sample app.
Finally, thanks to everyone that's been in touch with comments and ideas on how to make this widget better. I appreciate all the input
The MapView widget is a subclass of ViewGroup that provides a mechanism to asynchronously display tile-based images, with additional functionality for 2D dragging, flinging, pinch or double-tap to zoom, adding overlaying Views (markers), multiple levels of detail, and support for faux-geolocation (by specifying top-left and bottom-right coordinates).
It might be best described as a hybrid of com.google.android.maps.MapView and iOS's CATiledLayer, and is appropriate for a variety of uses but was intended for map-type applications, especially high-detail or custom implementations (e.g., inside a building).
A minimal implementation might look like this:
MapView mapView = new MapView(this); mapView.addZoomLevel(1440, 900, "path/to/tiles/%col%-%row%.jpg");
A more advanced implementation might look like this:
MapView mapView = new MapView(this); mapView.registerGeolocator(42.379676, -71.094919, 42.346550, -71.040280); mapView.addZoomLevel(6180, 5072, "tiles/boston-1000-%col%_%row%.jpg", 512, 512); mapView.addZoomLevel(3090, 2536, "tiles/boston-500-%col%_%row%.jpg", 256, 256); mapView.addZoomLevel(1540, 1268, "tiles/boston-250-%col%_%row%.jpg", 256, 256); mapView.addZoomLevel(770, 634, "tiles/boston-125-%col%_%row%.jpg", 128, 128); mapView.addMarker(someView, 42.35848, -71.063736); mapView.addMarker(anotherView, 42.3665, -71.05224);
The widget is straight java, so you can just use the .java files found here (with the dependencies mentioned below), or you can download the jar. Simple instructions are available here.
The source for a working app using the MapView is here. The compiled .apk for that demo is here.
If you're targetting APIs less than 12, you'll need the Android compatability lib for the LruCache implementation.
Jake Wharton's DiskLruCache is also used. Here's a direct link to that jar. However, that package is bundled with mapviewlib.jar so is only needed if you're using the java files directly in your project.
<dependency>
<groupId>com.github.moagrius</groupId>
<artifactId>MapView</artifactId>
<version>1.0.0</version>
</dependency>
Javadocs are here.
Licensed under Creative Commons