GPS 또는 인터넷을 사용하지 않고 Android에서 사용자의 현재 위치를 가져옵니다.
GPS 나 인터넷을 사용하지 않고 사용자의 현재 위치를 알 수 있습니까? 모바일 네트워크 제공 업체의 도움으로 말입니다.
당신이 찾고있는 것은 LocationManager.NETWORK_PROVIDER
대신을 사용하여 위치를 얻는 것입니다 LocationManager.GPS_PROVIDER
. NETWORK_PROVIDER
는 GSM 또는 와이파이에 의지 해결, 이제까지 가능합니다. 분명히 와이파이가 꺼지면 GSM이 사용됩니다. 셀 네트워크 사용은 기본적으로 500m까지 정확합니다.
http://developer.android.com/guide/topics/location/obtaining-user-location.html 에는 정말 훌륭한 정보와 샘플 코드가 있습니다.
에서 대부분의 코드를 완료 한 후 다음을 OnCreate()
추가합니다.
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
활동이 LocationListener
클래스를 구현하여 활동에 구현하도록 할 수도 있습니다 onLocationChanged()
.
을 얻음으로써 getLastKnownLocation
실제로 스스로 수정을 시작하지 않습니다.
이것은 공급자를 시작할 수 있지만 사용자가 이전에 위치를 얻은 적이 있다면 그렇게 될 것이라고 생각하지 않습니다. 문서는 이것에 대해 너무 명확하지 않습니다.
문서 getLastKnownLocation에 따르면 :
지정된 공급자로부터 얻은 마지막으로 알려진 위치 수정의 데이터를 나타내는 Location을 반환합니다. 이는 제공자를 시작하지 않고도 수행 할 수 있습니다.
다음은 빠른 스 니펫입니다.
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import java.util.List;
public class UtilLocation {
public static Location getLastKnownLoaction(boolean enabledProvidersOnly, Context context){
LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location utilLocation = null;
List<String> providers = manager.getProviders(enabledProvidersOnly);
for(String provider : providers){
utilLocation = manager.getLastKnownLocation(provider);
if(utilLocation != null) return utilLocation;
}
return null;
}
}
또한 새 권한을 추가해야합니다. AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
여기에서 GPS 및 네트워크 공급자를 사용하지 않고도 사용자의 현재 위치를 얻을 수 있습니다.
1 . Convert cellLocation to real location (Latitude and Longitude), using "http://www.google.com/glm/mmap"
boolean gps_enabled = false;
boolean network_enabled = false;
LocationManager lm = (LocationManager) mCtx
.getSystemService(Context.LOCATION_SERVICE);
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Location net_loc = null, gps_loc = null, finalLoc = null;
if (gps_enabled)
gps_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (network_enabled)
net_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (gps_loc != null && net_loc != null) {
//smaller the number more accurate result will
if (gps_loc.getAccuracy() > net_loc.getAccuracy())
finalLoc = net_loc;
else
finalLoc = gps_loc;
// I used this just to get an idea (if both avail, its upto you which you want to take as I've taken location with more accuracy)
} else {
if (gps_loc != null) {
finalLoc = gps_loc;
} else if (net_loc != null) {
finalLoc = net_loc;
}
}
아니요, 현재 GPS 나 인터넷을 사용하지 않으면 위치를 확인할 수 없습니다.
Location techniques based on WiFi, Cellular, or Bluetooth work with the help of a large database that is constantly being updated. A device scans for transmitter IDs and then sends these in a query through the internet to a service such as Google, Apple, or Skyhook. That service responds with a location based on previous wireless surveys from known locations. Without internet access, you have to have a local copy of such a database and keep this up to date. For global usage, this is very impractical.
Theoretically, a mobile provider could provide local data service only but no access to the internet, and then answer location queries from mobile devices. Mobile providers don't do this; no one wants to pay for this kind of restricted data access. If you have data service through your mobile provider, then you have internet access.
In short, using LocationManager.NETWORK_PROVIDER or android.hardware.location.network to get location requires use of the internet.
Using the last known position requires you to have had GPS or internet access very recently. If you just had internet, presumably you can adjust your position or settings to get internet again. If your device has not had GPS or internet access, the last known position feature will not help you.
Without GPS or internet, you could:
- Take pictures of the night sky and use the current time to estimate your location based on a star chart. This would probably require additional equipment to ensure that the angles for your pictures are correctly measured.
- Use an accelerometer to track location starting from a known position. The accumulation of error in this kind of approach makes it impractical for most situations.
Have you take a look Google Maps Geolocation Api? Google Map Geolocation
This is simple RestApi, you just need POST a request, the the service will return a location with accuracy in meters.
You can use TelephonyManager to do that .
It appears that it is possible to track a smart phone without using GPS.
Sources:
Primary: "PinMe: Tracking a Smartphone User around the World"
Secondary: "How to Track a Cellphone Without GPS—or Consent"
I have not yet found a link to the team's final code. When I do I will post, if another has not done so.
'developer tip' 카테고리의 다른 글
JavaScript에는 "단락"평가가 있습니까? (0) | 2020.09.08 |
---|---|
ADO.NET Entity Framework : 업데이트 마법사가 테이블을 추가하지 않습니다. (0) | 2020.09.08 |
명명 된 함수 식을 사용하는 이유는 무엇입니까? (0) | 2020.09.08 |
bash에서 alt + 숫자를 누르면 (arg [numeric])이 무엇입니까? (0) | 2020.09.08 |
-[UITableView _endCellAnimationsWithContext :]에서 어설 션 실패 (0) | 2020.09.08 |