2017-03-13 3 views
2

Google지도가 있습니다. 시뮬레이터에서 모든 것이 잘 작동하지만 안드로이드 장치는 현재 위치를 찾지 못합니다 (메시지 위치 오류 - 코드 참조). 세계지도에서지도가 열립니다 ...코드 명 Google지도

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