Reputation: 2629
I've used MapTiler to create some tiles that I'm trying to overlay onto a Google map with android and not having much luck. The Android documentation is pretty sparse on this topic but I've done what I think should work, yet I'm not seeing the tiles when I zoom in to the correct level. I'm trying to make the overlay happen in the onMapReady() callback, should I be doing that somewhere else?
Here's the code I have for the onMapReady method:
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.setMyLocationEnabled(true);
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(44.481705,-114.9378269)).zoom(16).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mTileOverlay = googleMap.addTileOverlay(new TileOverlayOptions()
.tileProvider((new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = "http://www.example.com/tiles/"+zoom+"/"+x+"/"+y+".png";
// added this logging to see what the url is
Log.d("home", s);
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
})));
}
any ideas here?
TIA
EDIT: I've adding some logging to see what 's' (my url) is returning, and it's returning the correct url and my server is serving up the tiles correctly from that url but still not seeing anything on the map in android.
Upvotes: 3
Views: 1646
Reputation: 2629
It turns out I had a toast in my getTileUrl() method that was preventing the images from being returned. When I removed that, the tiles were served correctly.
Upvotes: 1