I have some app that sends some information to the internet from time to time let say ones at day. And I can easily send some coordinates (using the gps position) but I do not want that. The android phone is always connected to the internet via wifi or mobile network. But not always enabled the gps. So is it possible to get the location with wifi or mobile network ? I google this thing and I end up with finding location by gps, I do not want to do that.
Can you give me some ideas what can I do this. I have seen web sites that when I open them they know where am I, so I guess it is possible to find the nearest name of the city just by making a internet request and reading the response or maybe use some service . . .
Thanks
http://developer.android.com/reference/android/location/package-summary.html
http://developer.android.com/reference/android/location/Address.html#getAddressLine(int)
getLocality looks like it may do what you want?
For websites that know where you are, they either use your source IP and look that up (which isn't very reliable for a lot of things), or they use the javascript geolocation APIs as described here:
http://merged.ca/iphone/html5-geolocation
In fact, here's a stack overflow answer on using google API to get to the city name:
Get city name using geolocation
Related
I would like to preface my query by saying that I am an absolute beginner when it comes to programming but I really want to realise this project so every little help is deeply appreciated.
I am trying to build an app that needs accurate train data for it to work and from my current research as there is not central government API for railway data , the only accurate data source for train location that I can find is in an other app that uses crowd sourcing to pinpoint the location.
I wanted to know if it is possible to fetch that train data from that app and then use it on my own as it would make my app a lot more reliable and accurate.
The issue currently is that the app only shows graphical representation of the data thats being fed to it from its servers , so I wanted to know if there is a way to access the actual data being sent to the app.
Thank you.
Let me clarify, this is a very broad question and hence will have a very broad answer too.
As far as I can understand from your question is that you want to show TRUE location on a map.
For this, you will have to understand the complete Tracking scenario. Let me explain it to you step-wise below:
There is an app, installed on a device (user) which fetches the GPS location (REAL) data and keeps sending it to a server (backend).
This GPS data is the Lattitude-Longitude coordinates of the device (user).
The server stores this information in their database for queries.
There is another user, different than the one currently sending the location data, who wants to know the location of the first user. The app which he is using will request the server (backend) to send the location data for the device. Which, in turn, will send the latest location data (LatLng coordinates) to the current app. This app will then show the location data over a map.
Now, usually, this process is followed to show one-to-one location data. However, in scenarios like Train Location etc, servers usually collect pool of location data, being received from several users, to cross-verify the actual location (average out, mean, location optimization algorithms etc.) and then display that information over a map.
As per your requirement, which I can understand, you want to get this REAL data directly from either another app or from the server. If you want to get the location data from the server, you will need an API, which serves as a Request-Response platform. However, if you are looking to get the data from another app, it would rather be simpler to get the location data directly, as your APP will also be installed on the device itself.
I would suggest you to kindly read about getting and processing location data, communication with servers over API etc for better understanding and implementation of your requirements.
Our intention is to filter the content based on location without requesting Location permission from the Android device,
In-order to meet this requirement, we have tried the following options and still its not reliable
Telephony Manager
it wont work without a Sim card, again say if the user from USA travels india now the below snippets returns US not India
var telephonyManager = context?.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val countryCodeValue = telephonyManager.networkCountryIso
Locale
Locale returns US or UK by default even if they are in India, usually user's Locale would be in English by default
Locale.getDefault().getCountry()
GPS
We doesn't want the Location permission to be requested
Retrieving the Country details form the logged-in Google account
Reply from Google - They dont have any dedicated API to retrieve countryCode of an user
Note:
iOS has a dedicated API which tell the CountryCode of the user, but Android doesn't
IP address
We tried to get the IP of the Android device (from several IP fusion websites), there are following two cases
User connected to WiFi - we are able to get the countryCode (WIFI IP
: 64.134.234.17)
User connected to Mobile Data - we are getting the wrong countryCode
even we are in USA, it says that IP is from JAPAN (MOBILE NETWORK
IP: 210.253.218.106)
Note:
Even Netflix determine the country during the launch, without requesting the Location permission
I think you have only two possibilities...or ask permission...or without asking permission you have to ask the user to insert an address (also only the city) and retrive the country code by mean of Google Geocoding Service
I agreed the above comments. You can't get the precise country by anyways other than there GPS location.
You can read this one hope you will get some idea about
Regarding your query how netflix is using it
https://help.netflix.com/en/node/26100
Brief
1.Disable any proxies (Means they are checking with there ip's)
2.Check your current IP address by visiting whatismyip.com (Same)
Regards
have you try using an API
ex:
http://ip-api.com/json
that will return country code and many other information all by analyze request IP "(no need obtained IP from device)" .
but obvious we need assume user not use any proxy or vpn
(There are plenty of other apis or you can implement and host one by yourself)
No way of getting it without Location permission, your better approximation is the localization by ip but as you saw there is no guarantee of precise localization
First of all I would like to mention that this would be done with the consent of all users!
That being said, what I am trying to create is an application where the users would see their location and the location of all the other connected users (latitude and longitude).
I am pretty sure the best way to do that would be to send data to a server and then have each device retrieve that data but I would like to know if there exist other ways of doing this. Or perhaps someone could point me in the right direction on how to create such a system with a server retrieving and sending data to android devices ?
GPS coordinates will do for you. You can get the coordinates and save in server then all the coordinates of a particular device can be retrieved by any connected device.
We have Location and LocationManager in android which shall do the job for you. Read more about these in the Android Developers
An application which uses Google Maps Api 2 has the advantage that all fetched map information are stored. Therefore they are available even when offline (no WiFi and no GSM). But if Internet is available it will download new data (the same data again) which is expensive when GSM is used.
Now I don't want to disable GSM entirely for Android. But only for the google maps object or say the application itself. I can't find any API function which can help me in order to allow googleMaps to (re-)download map information only when WiFi is available. So I have the choice between no internet at all or a pricy internet (when the application with google maps is active and already downloaded map information are redownloaded).
Is there a way to avoid this? Has anyone an idea how to override the regular googlemaps behaviour in order to control internet access or how a app can disable internet permission for itself temporary?
Thanks
Edit: To clarify - my question is: How can I disable the downloading of the tiles of a googlemap object without disable the object itself. I want to use the 'cached' tiles instead of redownloading it, which is expensive when using GSM. But I don't want to shut down GSM of my system so I'm available at chat clients e. g. whatsapp.
You can just identify the type of internet and then only call for certain methods if the proper type of internet is suitable for your needs.
In this answer from another post, you will find all you need to detect your type of internet:
https://stackoverflow.com/a/8548926/2074990
i am newbie to Android..i have latitude and longitude details in my program..i want to send them to web server via gps..and those details should be saved in a database and retrieve them whenever i require..plz explain me how to do..and if possible give me some sample code...
Did you mean the mobile network or wireless instead of GPS ?
Anyway:
You from the sounds of it you need to get the GPS details into your program then pass them to your server. Have you designed your webserver yet or are you going to be submitting this to a site that already exists?
You can't "send" something "via GPS". GPS is a "receive-only" thing.
http://en.wikipedia.org/wiki/Global_Positioning_System
If you like to send data to a web server, you can use the HTTP-protocol with Android, e.g. retrieve latitude and longitude (How to get Latitude and Longitude of the mobile device in android?) and then use HttpGet (or HttpPost):
http://developer.android.com/reference/org/apache/http/client/methods/HttpGet.html
You're really asking for a lot, but lets see if we can point you in the right directions.
Here is a great example of reading GPS data from an Android device:
LocationManager example
You must declare explicitly in Android that your app needs permission to access the Internet (and the GPS, for that matter).
Android Securty and Permissions
There are also some specific ways of life in Android development. The official developer's guide is a good place to start.
The Android Developer's Guide