gps없이 사용자 위치를 얻는 방법은 무엇입니까? 데이터 서비스 나 네트워크를 사용한다는 의미입니다. 가능한가? 누구든지 그것에 어떤 샘플 코드를 주시겠습니까?gps 또는 wifi없이 사용자 위치를 얻는 방법?
답변
에서 더 많은 데이터를 보이는 읽을 수 있습니다. 이 맥락에서 GPS와 네트워크를 프로 바이더라고 부릅니다.
내 로직이 작동하는 방식을 변경했으며, 활성화 된 공급자를 확인한 다음 사용 가능한 최상의 (GPS가 네트워크보다 좋음) 문자열을이 행에 반환합니다. String providerToSend = providers.get (1) ;, GetProvider 메서드에서. 그래서 각 공급자를 검사하는 대신에이 방법은 항상. NETWORK 문자열 인 providers.get (1)을 선택합니다. 귀하의 locationManager.getLastKnownLocation (TheStringWithTheCorrectProviderGoesHere)에 피드를 보내면 귀하의 위치가 반환됩니다.
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import java.util.List;
public class LocationService extends Service implements LocationListener{
protected LocationManager locationManager;
public String providerNow;
private List<String> providers;
public Location location;
private final Context mContext;
public LocationService(Context context) {
Log.i("TestMap", "LocationService");
this.mContext = context;
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0,this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,1000,0,this);
providerNow = (GetProvider());
}
public Location getLocation() {
location = locationManager.getLastKnownLocation(providerNow);
return location;
}
public String GetProvider(){
Criteria criteria = new Criteria();
criteria.setAccuracy(2);
providers = locationManager.getProviders(true);
String providerToSend = providers.get(1);
return providerToSend;
}
public IBinder onBind(Intent intent) {
Log.i("TestMap", "onBind");
//TODO for communication return IBinder implementation
return null;
}
public void onLocationChanged(Location location) {
Location locationNew = location;
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
providerNow = (GetProvider());
}
@Override
public void onProviderDisabled(String provider) {
providerNow = (GetProvider());
}
}
고맙습니다. 알았다. –
빈 생성자가없고 내 응용 프로그램이 작동하지 않는다는 이유로이 서비스를 활동에서 호출 한 행을 제공해 주실 수 있습니까? 고맙습니다. –
안드로이드 저장 마지막 위치는, U는 http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String)
많은 예 첫째 lastKnown 후 내 옷을 벗었 위치 서비스는 내가 지금 사용하고 있습니다 제공 how to get gps location android 다음
을 참조하십시오. "gps"위치를 얻는 방법을 알려줍니다 ... GPS가없는 경우. –
질문이 확실하지 않습니다. –
- 1. GPS 또는 WiFi없이 위치를 감지하는 방법은 무엇입니까?
- 2. 아이폰에서 GPS 위치를 얻는 방법
- 3. MapActivity가 시작될 때 GPS 또는 WiFi로 현재 위치를 얻는 방법
- 4. 다트와 GPS 위치를 얻는 방법? (모바일)
- 5. 백그라운드에서 30 분마다 GPS 위치를 얻는 방법
- 6. gps 위치를 자동으로 얻는 방법 android?
- 7. 30 분마다 안드로이드 GPS 위치를 얻는 방법?
- 8. GPS 좌표를 얻는 방법
- 9. 가장 정확한 사용자 위치를 얻는 방법
- 10. 리스너 또는 requestLocationUpdates없이 GPS 좌표를 얻는 방법
- 11. 안드로이드에서 GPS 위치를 추적하는 방법?
- 12. GPS 위치를 얻는 중 문제가 발생했습니다.
- 13. GPS없이 위치를 얻는 방법?
- 14. GPS에서 위치를 얻는 방법
- 15. 더 정확한 GPS 위치를 얻는 방법은 무엇입니까?
- 16. 서비스에서 사용자 위치를 얻는 중
- 17. android에서 내 위치를 얻는 방법
- 18. 스마트 폰의 방에서 정확한 위치를 얻는 방법 GPS 또는 blutooth 또는 다른?
- 19. Google이 사용자 권한없이 현재 위치를 얻는 방법
- 20. 새로운 Android 정책에 따라 사용자 위치를 합법적으로 얻는 방법
- 21. j2me 위치 API와 함께 GPS 및 네트워크 위치를 얻는 방법
- 22. 정적지도에서 점을 선택할 때 점의 GPS 위치를 얻는 방법
- 23. 자바 SE를 사용하여 USB/블루투스 GPS 수신기 위치를 얻는 방법
- 24. android에서 현재 위치를 얻는 방법
- 25. 주석의 위치를 얻는 방법 (//,/* 또는 * /) 정규식
- 26. asp.net에서 현재 사용자 위치를 얻는 방법
- 27. Google지도 v3를 사용하여 사용자 위치를 얻는 방법
- 28. GPS 신호 또는 장치의 GPS 타임 스탬프입니까?
- 29. 현재 위치를 얻는 방법
- 30. SMS를 통해 GPS 위치를 검색하는 방법
어떻게 https://developer.android.com/training/location/retrieve-current.html –
에 대해 인터넷에 대한 예제가 많이 있습니다. Google에서 검색하십시오. – Sunny
나는 거기에 갔다. 그러나 나는 나의 대답을 얻을 수 없었다. 도움을 청하는 것. –