开发者

Android, get latitude, longitude (wifi) and device ID

Is there an开发者_如何学编程y way to get latitude and longitude from the device without using the GPS? I would also like to know if theres a way to get some kind of serial number or similar.

Thanks


You can get your network/WIFI based location using the network provider property of the LocationManager class.

LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener);

Where listener is an implementation of the android.location.LocationListener class.

For your second question, you can get the WIFI MAC address which is pretty unique, although I'm not sure what happens if the device doesn't have WIFI.

WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
String macAddress = wm.getConnectionInfo().getMacAddress();

Note that this requires you to add the following to your manifest file

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


This might help: http://developer.android.com/reference/android/location/LocationManager.html

Try to use the networkprovider...

Here you can find some information related to that: http://androidforums.com/samsung-i7500/9257-using-wireless-networks-location.html

About a serial number i don't know... maybe you can use some kind of MAC adress...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜