Reputation: 2761
hi my app is sometimes used in rural areas where there is no 3g network so the first time the mapview loads it is really slow.
I would like to be able to to preload some tiles in the background ( in a service or in the main activity (home activity)) in order to speed up this download.
I have seen there is a method mapView.preLoad() but it only works with a mapView object. How could I do the same thing from a service? I thought to do like that:
MapView mv=new MapView(this, getResources().getString(R.string.MAP_API_KEY));
mv.preLoad();
problem is if the context is not a MapActivity this will throw an exception.
Here would be the flow of the app:
user starts app
main activity gets location data and stats downloading data for the map
user opens map activity
Map activity laods faster because it's downloaded data is already in the cache
any ideas of what I can do? thks in advance for advice
Upvotes: 2
Views: 2420
Reputation: 9217
I was using android Mapview
inside a fragment but when i load the map with coordinates it did not loaded at all. So i found a solution for this.
firt initialize the map in onCreate method.
View v = inflater.inflate(R.layout.fragment_layout, null);
map = (MapView) v.findViewById(R.id.map);
map.onCreate(this.savedInstance);
then set the map view like this.
private void setUpMap() {
try {
MapsInitializer.initialize(mContext);
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("Place Lable").icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_drawable)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15));
map.onResume();
}
this key point in this code is to call map.onResume();
after setting the Map
Upvotes: 4