I Want get location with Wifi and work in Google map, and it's not work for me but Gps is okay and not problem.
my code:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (locationManager != null) {
boolean gpsIsEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean networkIsEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (gpsIsEnabled) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 5000L, 10F,
(android.location.LocationListener) this);
} else if (networkIsEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 5000L, 10F,
(android.location.LocationListener) this);
} else {
// Show an error dialog that GPS is disabled...
}
} else {
// Show some generic error dialog because something must have gone
// wrong with location manager.
}
AndroidManifest:
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyB4C_zHeHYMTWqW4_Wpin-5jLF9S54KDSQ" />
</application>
<permission
android:name="com.karyan.karyanmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.karyan.karyanmap.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-feature android:name="android.hardware.wifi" android:required="true"/>
<uses-feature
android:name="android.hardware.camera"
android:required="false" >
</uses-feature>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
Newtork_Provider is null when wifi in connected to Intenet.. How to Resolve Problem
thanks..
Wi-Fi location tracking, also known as Wi-Fi Positioning System (WPS), takes the concept of Global Positioning System further. Instead of relying on satellites, it uses Wi-Fi routers and smart devices (Wi-Fi access points) to pinpoint a phone, tablet, or laptop more accurately than a GPS does.
To improve Location services and estimate the location of a device, Google uses publicly broadcast Wi-Fi information from wireless access points and GPS, cell tower, and sensor data. This data is limited to information about the wireless access point itself, including its location.
Your router gives Google no indication of its geographical location. In fact, it doesn't even present its IP address unless a device manages to connect to it (meaning that if you require a password to connect to your network, you're not broadcasting your IP address for the world to see).
If you are connected to WIFI then simply use NETWORK PROVIDER for your location updates. they will be fast and enough accurate too.
generally if location updates are not required so frequently then location updates are asked from both GPS and NETWORK together at the same time. whenever you get a location update of desired accuracy unregister from listening location updates.
But if location updates are required frequently then calling GPS can be a KILLER OF BATTERY too so be careful of using GPS PROVIDER.
GPS Updates are available good under open sky only. GPS Updates takes time , takes battery but Are More Accurate.
Network Updates are quicker, consumes less battery but are comparatively less accurate. But if we are talking about a WIFI accuracy it will be near to 50 or 100 that can serve many real time requirement.
It all depends on your requirement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With