Frage

How to get a users City and Country from an application in Android without GPS?

War es hilfreich?

Lösung

You can do it throug Cell tower or WiFi location. Or through PassiveLocation Provider. You can learn about it in this Google I/O video (min 20) http://developer.android.com/videos/index.html#v=twmuBbC_oB8

Andere Tipps

From a thread in the mailing list:

  • You could use the phone number which is assigned to you. The phone number starts with the country code.
  • Also the IMEI has information about in which country your phone was approved/registered.

"If you try to get information to which MNC-MCC you are connected use the TelephonyManager.getNetworkOperator() API. The MCC (mobile country code) is the information you are looking for."

Apparently, the simplest of all getLocale().getDisplayCountry() doesn't works at all so, without the location API, this is all you can do (besides Wi-Fi location).

Get users location via LocationManager.NETWORK_PROVIDER. Then use Geocoder to get address from location.

another solution would be to use a web service that detects the user's location via IP address.

http://ipinfodb.com/ip_location_api_json.php

You can also use the IP address, there is some webservices which will give you the location of the caller : http://free-web-services.com/web-services/geo/ip-to-location/

Pop up a dialog and ask them to enter a zip code?

Where else exactly would this "data" come from if not GPS?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top