Reputation: 283
I want to get latitude and longitude without using android Location Service
and Google Api
.
So Is there any way to get latitude and longitude from connected wifi
router ?
Upvotes: 0
Views: 693
Reputation: 2839
Try this code
This will give you longitude and latitude
Upvotes: 0
Reputation: 279
First of all get the IP Address using the following code:
public String getIpAddr() {
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipString = String.format("%d.%d.%d.%d", (ip & 0xff), (ip >> 8 & 0xff), (ip >> 16 & 0xff), (ip >> 24 & 0xff));
return ipString;
}
Please Note: You need to add android.permission.INTERNET and android.permission.ACCESS_WIFI_STATE in your AndroidManifest.xml as to access the code.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
After this use some 3rd party web service which gives you langitude and latitude by providing IP. Example : http://www.geoipservice.asmx/GetGeoIP?IPAddress= (PASS IP AS STRING)
Hope you got your answer!!!
Upvotes: 2