Google maps Android API getting wifi location

2020-07-30 05:52发布

问题:

So I am working on this app that will get the location of a wifi hotspot by just detecting it using the sensor wifi of the phone (The phone is not actually connecting to the hotspot wifi, it just detect). I was doing some preliminary research before start developing the app, and it seems that the Google Geolocation API will do the work for me. However, it is not free (at least what I understood after reading through the API). I had checked other apps that detects wifi hotspot, and I am just wondering if those apps have their own database with all the wifi hotspot information (SSID, location coordinates, etc) so when the wifi sensor detects a wifi hotspot, it will lookup the database and get the information such as location. Also, I was mentioned by a colleague that Google Maps also stores wifi info. Is is true? Cause I couldn't find any info about that.

回答1:

Android has multiple LocationProviders, including:

  • LocationManager.GPS_PROVIDER : get position using GPS
  • LocationManager.NETWORK_PROVIDER : get position using Wifi, cell network, etc.
  • LocationManager.PASSIVE_PROVIDER: get position using data provided by already running providers. This allows several apps to share geolocation information)

You don't have to pay anything to use NETWORK_PROVIDER
Some providers might not be present on all devices, depending on phone model and android version.

Providers have different characteristics: NETWORK is fast but not always precise enough, GPS is precise but slow and battery intensive, etc. The best strategy is to request location from several providers, and cancel pending request as soon as you get a location that is good enough depending on your criteria (precision, response time, etc.)

I found this article by Reto Meier quite useful to wrap my head around geolocation on Android