Hi,
I have developed an offline maps module for Android that has a bug where the user location is focused on instead of the offline map. What happens is that if the user moves the map to a location other than where the user is focused and saves the map for offline use then when the the offline map is displayed the user's location takes precedent and the offline map is shown offscreen, the user would have to swipe over to the offline map.
I have a method openOfflineMap that does the work of opening the saved map. Is there a way to always ensure that the offline map is displayed even if there is a user location? I have tried saving the offline maps lat/lng without luck. Any help is greatly appreciated.
Here is the code that opens the map:
private fun openOfflineMap() {
val offlineMapPackage = MobileMapPackage(offlineMapDirectoryPath)
offlineMapPackage.loadAsync()
offlineMapPackage.addDoneLoadingListener {
if (offlineMapPackage.maps.size == 0) {
mapNotDownloadedMsg!!.visibility = View.VISIBLE
progressBar!!.visibility = View.GONE
} else {
mapView!!.map = offlineMapPackage.maps[0]
callout = mapView!!.callout
progressBar!!.visibility = View.GONE
// downloadMapIcon.setVisibility(View.GONE);
mapView!!.visibility = View.VISIBLE
mapView!!.onTouchListener = object : DefaultMapViewOnTouchListener(context, mapView) {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (callout.isShowing()) {
callout.dismiss()
}
val screenPoint = Point(Math.round(e.x), Math.round(e.y))
// identifyResult(screenPoint);
identifyandDisplayResults(screenPoint)
return true
}
}
/*
val savedMapLat : Double? = sharedPreferencesPseg.getString("SAVEDMAPLAT").toDouble()
val savedMapLng : Double? = sharedPreferencesPseg.getString("SAVEDMAPLNG").toDouble()
CenterToJobLocation(savedMapLat, savedMapLng)
*/
}
}
}
Hi JohnMeah,
You can get the map's initialViewPoint (map[0].initialViewpoint) which you can use to set it on one of `MapView.setViewPointAsync` methods every time you load a new map from MobileMapPackage.
Thanks
Rama
Thanks, this works some of the time. I found that the initialViewPoint can be null. I'm using the code below which is working.
//Center to the map
if (mapView!!.map.initialViewpoint != null) {
Handler(Looper.getMainLooper()).post {
mapView!!.setViewpointAsync(mapView!!.map.initialViewpoint)
println("initial viewpoint works")
}
} else if (mapView!!.getCurrentViewpoint(Viewpoint.Type.BOUNDING_GEOMETRY) != null) {
Handler(Looper.getMainLooper()).post {
mapView!!.setViewpointAsync(mapView!!.getCurrentViewpoint(Viewpoint.Type.BOUNDING_GEOMETRY))
println("current viewpoint works")
}
}