Best way to get current address location Kotlin 2023 - android

I want to create a current location button to get the current address of the user. Currently I am using fusedLocationClient.lastLocation but its slow and sometimes it does not work.
Is there a better and updated way to get the current address from the user in 2023 using Kotlin.
Have a nice day!

The last comment (Jan 28) makes this question clear enough to answer:
A lat,lng location is already available, that is the starting point.
The goal is to obtain the the... a street address.
Currently this is done using geocoder.getFromLocation(latitute,longitude,1)
The problem is that this method is unstable and does not work sometimes.
The question is then: Is there anything else that I can use?
And the answer is: yes, with caveats.
First, please note that geocoder.getFromLocation() is provided by Android, for free but without guarantees:
Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do not use this API for any safety-critical or regulatory compliance purpose.
Since your concern seems to be the reliability of this service, a better solution may be provided by the Google Maps Platform Geocoding API, which does offer certain guarantees of latency and availability, as it is one of the Google Maps Platform Core Services.
The first caveat of this solution is that it is not entirely free of charge, see here How the Geocoding API is billed and consider what the cost would be for based on your user base and how often a latlng needs to be converted to an address. Make sure to restrict your API keys and optimize your usage.
The second caveat, which you might even like, is that this API doesn't return just one address, it tends to return a few. You can try this out using the Geocoder Tool at https://developers.google.com/maps/documentation/utils/geocoder (click on the map and it will reverse geocode that point).

Take a look at simple and step by step Google code lab:
https://codelabs.developers.google.com/codelabs/while-in-use-location/#1
You can also use and modify their complete template where is available on GitHub

Related

getFromLocation unstable Kotlin [duplicate]

I want to create a current location button to get the current address of the user. Currently I am using fusedLocationClient.lastLocation but its slow and sometimes it does not work.
Is there a better and updated way to get the current address from the user in 2023 using Kotlin.
Have a nice day!
The last comment (Jan 28) makes this question clear enough to answer:
A lat,lng location is already available, that is the starting point.
The goal is to obtain the the... a street address.
Currently this is done using geocoder.getFromLocation(latitute,longitude,1)
The problem is that this method is unstable and does not work sometimes.
The question is then: Is there anything else that I can use?
And the answer is: yes, with caveats.
First, please note that geocoder.getFromLocation() is provided by Android, for free but without guarantees:
Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do not use this API for any safety-critical or regulatory compliance purpose.
Since your concern seems to be the reliability of this service, a better solution may be provided by the Google Maps Platform Geocoding API, which does offer certain guarantees of latency and availability, as it is one of the Google Maps Platform Core Services.
The first caveat of this solution is that it is not entirely free of charge, see here How the Geocoding API is billed and consider what the cost would be for based on your user base and how often a latlng needs to be converted to an address. Make sure to restrict your API keys and optimize your usage.
The second caveat, which you might even like, is that this API doesn't return just one address, it tends to return a few. You can try this out using the Geocoder Tool at https://developers.google.com/maps/documentation/utils/geocoder (click on the map and it will reverse geocode that point).
Take a look at simple and step by step Google code lab:
https://codelabs.developers.google.com/codelabs/while-in-use-location/#1
You can also use and modify their complete template where is available on GitHub

Can we get Speed limit information from Waze APIs?

I've been trying to develop speed limit application & have tried many different approaches to get done .
I have used Overpass APIs & it did good but it did not have speed limit information for few of locations around Europe & also installed Velociraptor which uses OSM map & HERE Maps APIs still they failed to get data . Here is screenshot of Velociraptor app :
Yesterday I came across osmbonuspack & it looks promising as it allows us to choose from 3 best routing services available but Author of osmbonuspack told me that unfortunately, the 3 routing services are not returning speed limit information. Refer : Is it possible to get speed limit data using OSMBonusPack?
I have installed Waze application & it has speed limit data for locations around Europe which are not available from above options. So , anyone has a idea how they are getting information OR anyone knows which datasource they are using ?
Any suggestions would be appreciated.
I'm afraid Waze does not use another data source or at the very least not one unique data source that you could use. As a crowd-sourced application it relies on the information entered by map editors via the Waze Map Editor. Some editors might have used some open data sources available for their regions (if permitted by their local organisation), but it's far more likely they've used their local knowledge, Google Street View (Waze has a special license for that) or user reports sent in via the app.
As the map used by Waze is not open data, I'd highly advice against attempting to retrieve the speed data from their map. They have not exposed this information in an open API, which should be a strong indication that reuse of this data is not permitted.
OSM tagging is rich and flexible, but can be quite difficult to interpret.
Typically, max speed information is certainly there (the various routing services are based on it). The point is: how it's defined?
Have a close look here: http://wiki.openstreetmap.org/wiki/OSM_tags_for_routing/Maxspeed
And you will discover that getting maxspeed tag is not enough...
Then, refining your Overpass queries, maybe you will be able to get it everywhere!
Other hint: look at OSRM source code (or ask them), to see how they get this information.

How to create a naive location service for building specific accuracy

I want to build a prototype app that allows users to rope off a building such that when others open the app in that roped off area they can be located to that building without fail. Current geolocation services have many toss up scenarios that fail widely in many cases.
What could be a naive approach to overcoming this by potentially adding an additional service (like a simple wifi heat mapper) to clear up some of the location ambiguity in order to create a reliable bound over the location? Are their any APIs in existence to help with such a problem?
Are you talking about some specific buildings or any building that the user has entered? In the first case I would use beacons or IndoorAtlas. Both methods require you to visit the buildings and either install beacons or map it up with IndoorAtlas. With beacons it would be enough just to place one on each exit to keep track of who enters and exists the building.
There's really no possible way to reach building-level accuracy with a method that would be possible the extend to any building. The only exception would be some public buildings, which Google has mapped indoors (read more about the Google indoors project here). However, the list of available locations is still really limited.
Even though not optimal, the easiest way would be to use GPS/core-location for this project. According to our experiments, GPS never shows your location inside the building, where you are currently, but always about 15m outside of it. You could try placing a geofence that is slightly larger than the building itself outside of the locations you wish to use.
Whichever technology you end up using, you can try the Proximi.io API for a super simple solution of keeping track of the locations and geofences/beacons.

Can I exploit Google's implementation of getting the user location?

Ok the answer to my question is probably rather simple so let's get to it:
Is it possible to get the user's location directly from the Google Map like the myLocationLayer does it?
To be a bit more precise: I know that there are various possibilities to get the user location and that they are explained wonderfully in answers here on SO like this one. But the Maps API v2 seems so simple and it has so many nice gettters and setters that I can't but wonder if there isn't one to just set
GoogleMap.animateCamera(CameraUpdateFactory.goToUserLocation());
and let Google handle the satellite and network part. They already have the location (you can click on the myLocationsButton and go there immediately) so I would be rather suprised if this is not possible programmatically... But I did not find anything in the API v2 tutorial.
Thanks very much for your input
You may use GoogleMap.getMyLocation(). Note that it is depracted, but IMHO it should not be.

Implementing location tracking on Android

I am new to Android development and want to build a first sample application. My goal is to build a tracking application which sends my current location to a remote server. I want to use the collected data to calculate how many hours I spend in well known places like home or work.
Which approach should I use? I think it will be sufficient to use the information of present WLANs to get a good idea about the current location I am at. All the places I am interested in have WLAN with a static SSID. Are there any frameworks I should use or is there a better approach to what I am trying to do? GPS is not a real option, because the most interesting places are indoors and I have no GPS connection there.
I am working on Android 4.0.
As you say, GPS connection doesn`t work indoor, but it is very useful to estimate your current position. How? You could use the function getLastKnownLocation(best) that provides the LocationManager.
If you want to do it by yourself, you could try to get the last position by GPS, to locate a big area, and use the WLANs to estimate it with more accuracy, using the smaller group of radius with your interesting places.
You might want to read the Making Your App Location Aware training guide on the Android developer site. There's also an included sample application.
I actually am working on a similar project. Here is my code for location tracking on android; check it out. It tracks user's location regularly, uses Network location while indoor, and GPS when it could have a fix. It should give you a quick start.

Categories

Resources