Codenameone google 地图
Codenameone google map
我有一张 google 地图。在模拟器中,一切正常,但在 android 中,设备永远找不到当前位置(显示消息 Location Error - 请参阅代码)。地图在世界视图中打开...
cnt = new MapContainer(new GoogleMapsProvider(""));
cnt.setMapType(MAP_TYPE_TERRAIN);
LocationManager locationManager = LocationManager.getLocationManager();
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location loc = LocationManager.getLocationManager().getCurrentLocationSync(30000);
ipDlg.dispose();
if (loc == null) {
try {
loc = LocationManager.getLocationManager().getCurrentLocation();
} catch (IOException err) {
Dialog.show("Location Error", "Unable to find your current location, please be sure that your GPS is turned on", "OK", null);
return;
}
}
locationManager.setLocationListener(this);
if (loc != null) {
double lat = loc.getLatitude();
double lng = loc.getLongitude();
Coord coordinate = new Coord(lat, lng);
}
设备上的 GPS 处于活动状态。
我可以在其他应用中看到我的位置。
如果特定区域的 GPS 接收效果不好,您可以通过回退到某些默认位置来改进您的代码:
cnt = new MapContainer(new GoogleMapsProvider(""));
cnt.setMapType(MAP_TYPE_TERRAIN);
LocationManager locationManager = LocationManager.getLocationManager();
Location loc = locationManager.getLastKnownLocation(); //default
if (locationManager.isGPSDetectionSupported()) {
if (locationManager.isGPSEnabled()) {
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location loc2 = locationManager.getCurrentLocationSync(30000);
if (loc2 != null) {
loc = loc2;
}
} else {
Dialog.show("Location Error", "Unable to find your current location, please be sure that your GPS is turned on", "OK", null);
}
} else {
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location loc2 = locationManager.getCurrentLocationSync(30000);
if (loc2 != null) {
loc = loc2;
} else {
loc = LocationManager.getLocationManager().getCurrentLocation();
}
}
if (loc != null) {
double lat = loc.getLatitude();
double lng = loc.getLongitude();
Coord coordinate = new Coord(lat, lng);
}
我有一张 google 地图。在模拟器中,一切正常,但在 android 中,设备永远找不到当前位置(显示消息 Location Error - 请参阅代码)。地图在世界视图中打开...
cnt = new MapContainer(new GoogleMapsProvider(""));
cnt.setMapType(MAP_TYPE_TERRAIN);
LocationManager locationManager = LocationManager.getLocationManager();
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location loc = LocationManager.getLocationManager().getCurrentLocationSync(30000);
ipDlg.dispose();
if (loc == null) {
try {
loc = LocationManager.getLocationManager().getCurrentLocation();
} catch (IOException err) {
Dialog.show("Location Error", "Unable to find your current location, please be sure that your GPS is turned on", "OK", null);
return;
}
}
locationManager.setLocationListener(this);
if (loc != null) {
double lat = loc.getLatitude();
double lng = loc.getLongitude();
Coord coordinate = new Coord(lat, lng);
}
设备上的 GPS 处于活动状态。 我可以在其他应用中看到我的位置。
如果特定区域的 GPS 接收效果不好,您可以通过回退到某些默认位置来改进您的代码:
cnt = new MapContainer(new GoogleMapsProvider(""));
cnt.setMapType(MAP_TYPE_TERRAIN);
LocationManager locationManager = LocationManager.getLocationManager();
Location loc = locationManager.getLastKnownLocation(); //default
if (locationManager.isGPSDetectionSupported()) {
if (locationManager.isGPSEnabled()) {
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location loc2 = locationManager.getCurrentLocationSync(30000);
if (loc2 != null) {
loc = loc2;
}
} else {
Dialog.show("Location Error", "Unable to find your current location, please be sure that your GPS is turned on", "OK", null);
}
} else {
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location loc2 = locationManager.getCurrentLocationSync(30000);
if (loc2 != null) {
loc = loc2;
} else {
loc = LocationManager.getLocationManager().getCurrentLocation();
}
}
if (loc != null) {
double lat = loc.getLatitude();
double lng = loc.getLongitude();
Coord coordinate = new Coord(lat, lng);
}