Google Map offline not working if installed without internet connection - android

I've downloaded map tiles from http://tile.openstreetmap.org. What I want to do is use this map tiles with google map Library. I've followed the this links
- How to show google map offline?
- Google Map Offline
- TileProvider using local tiles
And have working map activity.
Here is CustomTileProvider class
public class CustomTileProvider implements TileProvider{
public Tile getTile(int x, int y, int zoom) {
Log.e("TAG","Get tile image");
byte[] image = readTileImage(x, y, zoom);
}
}
The problem I'm currently facing is when I uninstall the app and install, and run whithout internet connect the getTile method never been called. Can any body know why this is happening?
Edit:
I've stored the downloaded tiles inside assets folder with the following file structure
/map
/zoom/
/x
/y

Related

Create draw route direction with offline Google Maps

I was just wondering as to how to draw route direction(two point) of Google Maps in order for it to work offline. We have already downloaded offline Google Maps and then want navigation but do not know how to.
I was thinking of creating a navigation system with offline Google Maps, but I don't know how to draw route direction offline Google Map to work offline then embed it within my own application.
I have already used #mapbox Sdk, but my issue was I have downloaded offline location in Google Maps, after this location search any direction used two point direction in map, so I can drawline easily.
Using this : https://www.mapbox.com/android-sdk/examples/offline-manager/
Please help me on this one..
Could you clarify how exactly you are getting Google Directions API to work offline, to my knowledge the API only works online? Drawing the route can be done in a few different ways. The simpliest would be to convert the linestring the directions API gives you into multiple positions and then feed them into the polyline:
private void drawRouteLine(DirectionsRoute route) {
List<Position> positions = LineString.fromPolyline(route.getGeometry(), Constants.PRECISION_6).getCoordinates();
List<LatLng> latLngs = new ArrayList<>();
for (Position position : positions) {
latLngs.add(new LatLng(position.getLatitude(), position.getLongitude()));
}
routeLine = mapboxMap.addPolyline(new PolylineOptions()
.addAll(latLngs)
.color(Color.parseColor("#56b881"))
.width(5f));
}

Google maps custom tiles load slow

I'm trying to use Google Maps with custom tiles. For this, I use the API demo's from Google:
https://github.com/googlemaps/android-samples
and as an example I used TileOverlayDemoActivity as a base. Everything works as expected, but when you zoom in/out and the zoomlevel changes, all the tiles disappear and are being build up again, resulting in a gray screen of about one or two seconds. When you later-on zoom to this level again, the issue is not there, but, if you restart the app, it is there again!
Here is a recording I made from the API Demo's app (this is as-is, I have not changed anything) : https://www.youtube.com/watch?v=OZ3aqLOZ2CY
First I thought the downloading of the tiles took some time, so I tested with using a lightweight TileProvider:
public class MyTileProvider implements TileProvider {
#Override
public Tile getTile(int i, int i1, int i2) {
return new Tile(256, 256, byteArray);
}
}
where byteArray is always the same, created from a `Bitmap once:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
But here, still the same issue.
I don't think there is a solution to this issue, as I haven't found any on the web.
But if someone has a workaround, I could accept that. I am thinking of trying to zoom in from top to bottom for each level so they are drawn once (as I don't see this issue after a zoomlevel has been drawn)
I have a workaround for this and answered it on a different question here

What's the url to download map tiles from google maps?

I'm developing an android app using google maps android sdk v2 and want to allow users to download maps and use them offline.
To display the tiles I use a custom TileProvider implementation as described here.
I need to know the URL to download a google maps tile (vector tile if possible) based on latitude, longitude and zoom parameters (e.g. something like this )
Before anyone comments that it's violating google maps' terms, I can tell you it's ok to download a small amount of tiles specifically for this use case (see section 10.5.d in their terms here).
This is the link
http://mt1.google.com/vt/lyrs=y&x=1325&y=3143&z=13
lyrs parameters are :
y = hybrid
s = satelite
t = train
m = map
By Overriding getTile in your TileProvider, You get the needed X and Y and Zoom. there is no need to do anything.
#Override
public Tile getTile(int x, int y, int zoom) {
// DO YOUR STUFF HERE
}

How to Implement Google Map Tile Provider in android?

I am working on custom map app and i want to use google map tiles for background ? There is one class TileProvider in api but i don't know how to initialize it every time i try it goes something like this ?
TileProvider tileProvider=new TileProvider() {
#Override
public Tile getTile(int i, int i2, int i3) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
};
how to override getTile function to get tiles from google map server?
Any example will be appreciated ?I know getTile function need x,y and zoom value to return tile.
So quick answer is that you can get the Google Map tiles from the following URL:
http://mt1.google.com/vt/lyrs={t}&x={x}&y={y}&z={z}
Where {t} is the type of map (satellite, road, hybrid, etc) and the other attributes are specifying the coordinates and zoom level.
The possible values for {t} are as follows:
Default - m
Roads only - h
Roads simplified - r
Satellite - s
Satellite hybrid - y
Terrain - t
Terrain hybrid - p
That being said you do want to make sure what you're doing is NOT a violation of the terms & services. Specifically Google WILL allow you to cache their tiles provided that you are doing so ONLY in order to improve performance and that you delete their tiles at least every 30 days, and finally you don't pull down their tiles in an attempt to make your own mapping service.
You may want to read the Google Maps Terms of Service - https://developers.google.com/maps/terms - specifically section 10.1.1

Google Maps advanced features in a MapActivity (Google Maps API)

I wanted to load a custom KML file on the map. I chose the simple way:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, url);
And it works well, but obviously I can't control various features like custom icons for overlay items, or the popup "Loading myKml.kml..." that shows everytime I start it, etc.
First question:
Aren't there any parameters to setup when I start a Google Maps Intent, to tweak my map? I can't find anything on the documentation.
So I was thinking about using the Google Maps API for my app. Well, I've managed to load my KML file parsing it with a SAX parser and creating a custom overlay for my map.
It works, but there is a great problem:
The placemarks aren't loaded dynamically in relation to my position. They are loaded from the start to the end, and are shown on the map 100 at time.
So it was going to be harder than I thought, because I'll have to get my position from the GPS and calculate only the nearest points and draw them on the map.
Second question:
Does exist a built-in function to show only near-to-me placemarks on the map?
Thank you, guys.
2nd question. No. Have a look at LocationManager.addProximityAlert(double latitude, double longitude, float radius, long expiration, PendingIntent intent).

Categories

Resources