2017-03-13 5 views
2

私はGoogleマップを持っています。シミュレータでは、すべて正常に動作しますが、アンドロイドデバイスは現在の場所を検出することはありません(メッセージロケーションエラー - コードを参照)。地図は世界視界で開きます...コードネームgoogle map

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の受信が特定の領域では良いではない場合

答えて

1

あなたは、いくつかのデフォルトの場所に戻って落下することにより、あなたのコードを向上させることができます

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); 
} 
+0

感謝を。デフォルトの場所が機能しました。地図でフォームを開くのに非常に時間がかかります... 20/30秒...それは普通ですか?私がフォームに戻って再入力に時間がかかると...無限の進歩を示しているので、場所を見つけるのに非常に時間がかかると思っています... – atmenezes

+0

このプロセスは ' postShow() 'ではなく、' beforeShow() 'にはありません – Diamond

+1

また、InfiniteBlockingを使用しないでください。私が通常行っていることは、ツールバーの右上や他の場所にInfiniteProgressを追加し、プロセスが完了したらそれを削除することです。 – Diamond