What Country is the User Currently In? - android

I've looked around a bit on stackoverflow and Google Groups and haven't really found an answer for this exact question.
I simply want to be able to know what country the user of an Android phone is currently in.
I assume the TelephonyManager doesn't work if the user is using wifi only. Is this true?
We've tried passing the user's current latitude and longitude using android.location.Geocoder, but it's really flaky. It will frequently return empty results. Sometimes we can keep asking it and it will eventually return results, but it's really ugly. Is there a more reliable way?
Thanks,
Rob Sz

You could try reverse Geo Coding :)
http://code.google.com/apis/maps/documentation/geocoding/
Check this link. The country is returned in JSON.
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
I honestly do not know whether this will work in all scenarios but I believe this is something that can help.
EDIT: Looks like it kinda works :)
Tried with my country and seems to work perfectly.
http://maps.googleapis.com/maps/api/geocode/json?latlng=6.822716,79.878159&sensor=false
You will get
{
"status": "ZERO_RESULTS",
"results": [ ]
}
for example, if the user is in the middle of an ocean by any chance :P

What about using an IP-based geolocation service? I would guess that due to regulatory differences network divisions are usually fairly country specific, except in cases such as corporate VPN's where you are virtually plugged into the net somewhere else?

Try using a web service, like Chris suggested. Here's a list of a few that will do the trick:
http://free-web-services.com/web-services/geo/ip-to-location/
I'm using http://www.hostip.info, which is nice and simple.

Related

Geocode Autocomplete mobile

I am trying to set up autocomplete with geocoding. If the user is typing in a name of a city, I want him get a few cities as a result. Vice versa with postal codes.
The new policy from google seems way too expensive (70.000 autocomplete requests = 200$ ?? )
I tried to solve it with the Xamarin.Forms.Maps.Geocoding implementation, but this does not seem to work at all... at least not under iOs. The result of GetPositionsForAddressAsync or GetAddressesForPositionAsync does return a List, but no matter what input I provides, it only contains just one value.
So in your opinion: What ist the best and cheapest way to accomplish a geocoding autocomplete solution? I have no problem spending money for it... I am just looking for the best solution.
You can take a look at OpenStreetMap based geocoders with autocompletion support, e.g. Photon. It's open-source as well.

How to get exact location inside building?

Is there any workaround get exact location inside building or still it's not possible..
I've checked few things like
https://developer.foursquare.com/docs/venues/venues
http://www.walkbase.com/
http://www.directionsmag.com/articles/10-things-you-need-to-know-about-indoor-positioning/324602
But didn't able to find what I want!!
I want my app to know weather user in in particular restaurant or not!! I'v also tried http://developer.android.com/training/location/geofencing.html
but not sure how to use it..
It'll be great if someone help me with where to start and which is best?
Thanks :)
no it is not possible. some companies experiment: for some buildings, that have to be measured to the specific technologiy that those companies use, it may work a bit, but not in general case.
if you want to know the restaurant, enable gps before the user enters the restaurant.
that way you get the position via gps when the user stands before the restaurants door.
as long as the restaurant is not inside a huge indoor shopping center, chances are good.

Querying the time using Google Search Results

This one is puzzling me...
For my Android application I want to be able to return the current time in any location the user requests (right down to city level). The request itself comes from a voice command, so I cannot use alternative methods.
The most obvious way (so I thought) was to query Google, but I need your brains to help me solve how to extract the data I want please!
In Google, query:
"What's the time in China"
You should see a 'widget' at the top displaying the answer nicely. View the page source and search on 'China' and it's there - I thought great, this is going to be easy!
But...
"What's the time in London"
Although the display in Google appears the same, there is no result for 'London' when searching the source HTML...?
Using Google Chrome, I inspect the element of the 'widget' and can then view the contents I wish to extract in all cases.
So, my questions is firstly, am I missing something obvious (Google don't want us to be able to do this for example)? Or is there a way to 'force' the result to be in the HTML by structuring the query perhaps?
Secondly, is there a way to access the specific 'element container' and return the results to my Android Application?
I thank you in advance...
You should really use an API instead of parsing html.
I guess there are many many API which will give you the time in a given city.
http://www.worldweatheronline.com/time-zone-api.aspx for example (havnt tried it myself)
If you still want to extract data from the google result (which is html), check for html parsers like in this post : Parse HTML in Android

Get the user's approximate location without GPS / WiFi / Internet

I'm trying to find a way of checking if the user is in the US, and do it somehow that it's instant. This means no GPS, and no internet.
I have a few ideas, but they're not as accurate as I'd want, so maybe someone here has some tricks up his/her sleeves.
Thanks!
I've just been looking at http://developer.android.com/guide/topics/resources/providing-resources.html and on table 2 there's some resource qualifiers for 'MCC and MNC' and 'Language and region'.
What about defining some resource, say a string indicating the country code, then setting up a different one for each country you are interested in.
You could then look at the string to see what country you are in. I guess you'd need a bit of experimentation to see what works best, but it might work :-)

How to implement a search like the google maps address search?

I would like to create a search in my app which acts like the map search in the Google Maps app.
I have creates an an auto complete text view which updates dynamically based on the results of the Geocoder.GetLocationByName() Method.
However the results retrieved from this function are really bad and not at all consistent with the text I pass to it.
Is there a better method of doing this to achieve accurate results?
So it's not the geosearch that's your problem, but the autocompletion, right? Well I assume you need the whole set of possible values in order to obtain a decent auto-completion. Another way would be to take apart the google javascript code that performs the auto-completion and talk to their servers, pretending you're typing into one of "their" fields. However, this isn't only probably against their terms of service but also a bit shaky because they might a) detect and prevent this or b) change their interface in the future.
Your best guess would be to get a list of all cities, streets, etc in question.
hopefully this should be able to do the trick :=)
https://developers.google.com/places/documentation/autocomplete
good luck (testing it myself right now)

Categories

Resources