简体   繁体   中英

Codenameone native maps offline?

it was brought to my attention that when I use the native maps in codenameone , and try to change the camera position the maps get blank , is there anyway that I could use the native maps functionality with no internet connection

final String HTML_API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
 final MapContainer cnt = new MapContainer(HTML_API_KEY);
cnt.addMarker(EncodedImage.createFromImage(MarkerImg, false), new Coord(latitude, langitude), "", "", e3->{
});
Container root = LayeredLayout.encloseIn(
BorderLayout.center(cnt)
);
mapForm.add(BorderLayout.CENTER, root);
mapForm.revalidate();

Update :

The exception that I face on IOS when using the offline method :

MBTilesProvider provider = null;
        try{
            if ( MBTilesProvider.isLoaded("xxxxx.cn1tiles") ){
                provider = new MBTilesProvider("xxxxx.cn1tiles");
            } else {
                provider = MBTilesProvider.create("xxxxx.cn1tiles",fetchResourceFile().getData("xxxxx.cn1tiles"));
            }
        }catch(Exception e){
            e.printStackTrace();
            new GlobalOperations().ShowDialog(null, "OffLine Map", "there was a problem with loading the map file "+e.getMessage());
            return;
        }

java.lang.NullPointerException
    at ca_weblite_codename1_mapbox_MBTilesProvider.create:221
    at userclasses_StateMachine.beforeMap:5850
    at generated_StateMachineBase.beforeShow:5850
    at com_codename1_ui_util_UIBuilder.showForm:2518
    at com_codename1_ui_util_UIBuilder.showForm:2565

appreciate the help to make the map work with no internet connection

Regards,

The Google Native Maps don't support offline functionality as far as I know although their app has some support for that. You can use this which doesn't offer the same level of UX as the native maps but works offline: https://github.com/shannah/CN1OfflineMaps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM