Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TileOverlay with android and google maps

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.

like image 844
Christopher Johnson Avatar asked Mar 02 '26 21:03

Christopher Johnson


1 Answers

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.

like image 103
Christopher Johnson Avatar answered Mar 04 '26 09:03

Christopher Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!