2015-01-19 5 views
0

내 애플 리케이션에서 장치의 위치를 ​​얻으려고합니다. 위치 서비스가있는 경우 앱이 정상적으로 작동합니다. 그러나 위치 서비스가 android에있는 경우 위치 서비스가 꺼져 있고 주소를 입력하라는 메시지가 앱에 표시되기를 원합니다. 내 코드이 코드는하지만 안드로이드 장치에서 로컬 컴퓨터 크롬에서 일하고안드로이드 webview 위치 리디렉션

if (navigator.geolocation) { 

      navigator.geolocation.getCurrentPosition(init_pos,showerror); 
     } 
     else { 

      window.open("Location.aspx", '_self', location = true); 
     } 

     function showerror(error) { 
      switch (error.code) { 
       case error.PERMISSION_DENIED: 
        window.open("Location.aspx", '_self', location = true); 
       break; 
       case error.POSITION_UNAVAILABLE: 
        window.open("Location.aspx", '_self', location = true); 
       break; 
       case error.TIMEOUT: 
        window.open("Location.aspx", '_self', location = true); 
       break; 
       case error.UNKNOWN_ERROR: 
        window.open("Location.aspx", '_self', location = true); 
       break; 
      } 
     } 

    } 

    function init_pos(position) { 
     lat = position.coords.latitude; 
     long = position.coords.longitude; 

     window.open("home1.aspx?lat=" + lat + "&lng=" + long, '_self', location = true); 

    } 

입니다.

답변

-1

안드로이드 기기의 GPS 사용 여부를 확인하려면 아래 스 니펫을 사용할 수 있습니다.

private LocationManager locManager; 
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
//GPS enabled  } 
else 
{ 
//GPS not enabled 
} 

그리고 현재 위치를 얻으려면 게시 된 코드에서 아무 것도 얻을 수 없습니다. 더 나은 이해를 위해이 모양을 살펴보십시오. http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/