Caching temporarily a part of a Map (MapView)
I'm developing an application with the MapView and the GPS. My problem is that the user might disconnect while using my application,开发者_开发知识库 so he'll be walking in a fully grey map. I'd like to cache the map temporarily in order to see it later. I know that cache the map isn't allowed by the google maps API, but I want to be sure if TEMPORARILY cache it (and delete it when the app is closed) is also forbidden.
I've heard about openstreetmaps / osmdroid, but I'd like to confirm that I HAVE to use it before deleting half of my code.
I know that cache the map isn't allowed by the google maps API, but I want to be sure if TEMPORARILY cache it (and delete it when the app is closed) is also forbidden.
There is no means of accomplishing this with the Google Maps Add-On for Android.
Because I need the satelliteView, I finally used a method that could be improved.
I start a thread that asks the controler to go to a location near the user. It's downloaded and the cache is managed by the MapView:
int latitudeSpan = mapView.getLatitudeSpan();
int longitudeSpan = mapView.getLongitudeSpan();
for(int i=-MEMORIZED_MAP_SIZE;i<=MEMORIZED_MAP_SIZE;i++)
{
for(int j=-MEMORIZED_MAP_SIZE;j<=MEMORIZED_MAP_SIZE;j++)
{
synchronized (this)
{
if(i==j&&j==0) j++;
Message msg = new Message();
msg.arg1=latitude+latitudeSpan*i;
msg.arg2=longitude+longitudeSpan*j;
msg.setTarget(MainActivity.handler);
msg.sendToTarget();
try
{
wait(5000);
}
catch(Exception e){}
}
}
}
Now, I just need to find another way than "wait(5000)" to know that the part of the map I'm looking at is downloaded. I'll modify this message if I find one.
Do you have the whole example of this?
int latitudeSpan = mapView.getLatitudeSpan();
int longitudeSpan = mapView.getLongitudeSpan();
for(int i=-MEMORIZED_MAP_SIZE;i<=MEMORIZED_MAP_SIZE;i++)
{
for(int j=-MEMORIZED_MAP_SIZE;j<=MEMORIZED_MAP_SIZE;j++)
{
synchronized (this)
{
if(i==j&&j==0) j++;
Message msg = new Message();
msg.arg1=latitude+latitudeSpan*i;
msg.arg2=longitude+longitudeSpan*j;
msg.setTarget(MainActivity.handler);
msg.sendToTarget();
try
{
wait(5000);
}
catch(Exception e){}
}
}
}
I managed to solve this partially using 2 MapView Fragments , one of them invisible. Then a loop was moving the camera to create cache for the other MapView
精彩评论