Android dev
Android dev

Reputation: 283

Can we get latitude longitude without using location api or google api

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

Answers (2)

Vishwesh Jainkuniya
Vishwesh Jainkuniya

Reputation: 2839

Try this code

code

This will give you longitude and latitude

Upvotes: 0

prashant0205
prashant0205

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

Related Questions