React native queries GPS coordinates and gives timeout - android

We have the next problem:
We are consulting the gps location in order to get a list that contains only those that are close in a radius, but when consulting the GPS it gives us timeout after at leat 40 seconds of waiting.
The problem especially occurs in Android with a Xiaomi Redmi 8 in industrial environments, with less connection than usual or on the move, they donĀ“t have access to LTE all the time.
We use the library # react-native-community / geolocation or navigation.position
Can you help us with any other library or strategy to obtain GPS position that does not consists in the gps wacthing changes on its position all the time? something like getting it on the background..
Code
Geolocation.getCurrentPosition(
position => {
// process the position
},
error => {
console.log(error);
}, {
timeout: 40000,
maximumAge: 0
}
);

As cited from library's github page:
Currently, on Android, this uses the android.location API. This API is not recommended by Google because it is less accurate and slower than the recommended Google Location Services API. This is something that we want to change in the near future https://github.com/react-native-community/react-native-geolocation/issues/6.
There also are some library suggestions in the readme, that actually use Google Location Services API. I've used react-native-location, but this package isn't actively maintained anymore, so I switched to react-native-geolocation-service, which has a very similar API to what you're already using, more specifically the getCurrentPosition.
Perhaps you should give it a try.

react-native-community/geolocation does not utilize the more accurate Google Location Services API, as stated in readme
The recommended library for GPS location (and the one I used) for RN Android is react-native-geolocation-service. Its Readme also mentions a timeout issue which makes me wonder if it is the same as yours:
This library is created in an attempt to fix the location timeout
issue on android with the react-native's current implementation of
Geolocation API. This library tries to solve the issue by using Google
Play Service's new FusedLocationProviderClient API, which Google
strongly recommends over android's default framework location API. It
automatically decides which provider to use based on your request
configuration and also prompts you to change the location mode if it
doesn't satisfy your current request configuration.
So if I were you I would give it a go. The API is meant to be a drop-in replacement for the library you used so migrating should be just a matter of changing packages.

Related

Android Google Maps Offline - my location is not shown

I am trying to use Google Maps for Android, offline (always and forever).
Surprisingly, I can't find any question here that asks or solves this issue specifically.
When I use a new offline phone, both my app and Google Maps show a blank map (dah, no map loaded) and 'my' location blue dot is not shown. Well, actually, no marker is shown.
To Reproduce
Restore any Android phone to its factory settings
Enable location services (GPS, without connecting to the internet at any stage)
Open the Google Maps app
--> See that there is no 'my location' blue marker, although when you long click on the screen, the app shows its coordinates (meaning, GPS does work, but the map doesn't show it)
Technical Symptoms
Even when I load offline maps (.mbtiles format, custom ones, not Google's) they're still not shown (nor the markers). It's like Google put some code like this:
if (no internet) hideAllViews().
Note that once I connect the phone to the internet, our custom tiles do work, even if I later turn the phone offline.
I can interact with the map (long click to view the clicked location, for example, which shows that my GPS location indeed works), but that's about it (until I connect the phone to the internet, from which point I can turn it offline again but with everything surprisingly working).
Code Example - a simplified version
//build.gradle:
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//MapActivity.kt
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.MapsInitializer
class MapActivity : AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.map_activity)
val mapFragment = supportFragmentManager.findFragmentByTag(MAP_FRAGMENT_TAG) as MapFragment?
?: MapFragment().also {
supportFragmentManager.beginTransaction().add(R.id.map, it, MAP_FRAGMENT_TAG).commit()
}
mapFragment.getMapAsync(::onMapReady)
mapFragment.retainInstance = true
}
private fun onMapReady(map: GoogleMap) {
map.isMyLocationEnabled = true
map.uiSettings.isMyLocationButtonEnabled = true
Log.d("GoogleMap", "Map should be ready and visible with my-location marker shown, if phone's GPS is enabled")
}
}
I hope someone here knows a trick or worked at Google and can shed some light on this.
Thank you!
As opposed to most similar questions, I do know how to make this work (internet...) but am asking specifically about a use case where a new phone can never be connected to the internet - not even one time for one second.
I am familiar with other offline maps services, but am trying to solve this with Google's maps, at least for now
It is not possible to load the API without connecting to the internet first since it was designed to be used online(As of now), so this is Working As Intended.
Please note that using Maps SDK for android requires an internet connection first to load because it checks the API key. Then you can use the Map offline for a certain period of time(there's no definite period of time for offline functionality that requires you to be online again)
But there are customers who are also interested in this functionality, so there is an ongoing entry for it in the Google Issue Tracker that was created since 2013 to let the API users be aware of this feature request.
You can view and star the feature request here:
https://issuetracker.google.com/35823181
Please note that the Issue Tracker entry above is the authoritative source for public information regarding the aforementioned feature requests, and all publicly-relevant updates will be posted there.

react-native-google-places ERROR making places detection api call: ERROR

this is the code that the docs in the googleplace but this is happend
ERROR making places detection api call: ERROR
RNGooglePlaces.getCurrentPlace()
.then((results) => alert(results))
.catch((error) => alert(error.message));
According to this GitHub issue, assuming you're using tolu360's react-native-google-places library, you should check the following:
Ensure device's GPS location is on.
Ensure you have asked for (and received) ACCESS_FINE_LOCATION permission.
Ensure you are using a real device, not an emulator.
Since you need a specific place, you need a real device with the ability to report it's location, and permission to access that information!
On line 363 of RNGooglePlacesModule.java inside the library, you can add a breakpoint to see the actual error returned by likelyPlaces.getStatus(). I suggest you do this and add any extra information into your question.

Tracking locations of Android applications with geolocation-API

Is it possible to use http://www.w3.org/TR/geolocation-API/ to track location of Android
application without using android.location.Location, android.location.LocationListener,
import android.location.LocationManager classes. I hope by using geolocation API can provide
same API for all mobile platforms to get the GPS. Appreciate if you can provide an example for
geolocation-API.
How can I get my android mobile location using geolocation-API.?
There is other thread on this topic , which does identify that this API should work just fine, provided that you are defining the permissions in manifest file.
Also as the API is used in web-environment, you would need to then have the code executed in one, for example by using the webview as was with the other question.

Osmdroid and Mapnik tile provider no longer working

I have a developed, deployed and previously successful application which uses Osmdroid to load tiles from the default tile provider which is Mapnik
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
or
mMapView.setTileSource(TileSourceFactory.MAPNIK);
Until recently (maybe since today) the tiles on real devices (a phone and a tablet) do not load anymore. I am using osmdroid version 3.0.5. If I try the latest 4.0 version in a small sample project on an emulator, I see '403 forbidden responses' in the logcat when trying to download maptiles. If I switch the tile source to
mMapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
then the map is visible with no problem. I don't see any reported issues on the
Osmdroid web site issues list, nor does a Google search reveal any new problems reported, so I am asking if anyone else sees this new behaviour from Mapnik and might know of a fix?
Please follow Issue 515 to track this issue. We have implemented a fix and we will release a proper update soon.
Having the same problem as well.
Unfortunately, it seems that osmdroid was banned from accessing http://tile.openstreetmap.org. Reading the tile usage policy, I found these two things which might explain why osmdroid got banned:
Heavy use (e.g. distributing an app that uses tiles from openstreetmap.org) is forbidden without prior permission from the System Administrators.
and
Valid User-Agent identifying application. Faking another app's User-Agent WILL get you blocked.
(osmdroid's useragent is "Apache-HttpClient/UNAVAILABLE (java 1.4)" which is pretty generic)
From OpenPisteMap:
If you start getting "403 Forbidden" responses, stop. Don't just
keep hammering away at the server - it probably means that you've been
banned for abusive behaviour and continuing to hammer away at the
server will just extend your ban.
http://wiki.osm.org/wiki/Blocked
You can use this code to set the user agent
HttpClientFactory.setFactoryInstance(new IHttpClientFactory() {
public HttpClient createHttpClient() {
final DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "useragent");
return client;
}
});

Google Maps Android API v2 - APIs related to my location deprecated. Why?

Since the Google I/O 2013 we can read in several places of the documentation of Google Maps Android API v2 that
This method / interface is deprecated.
use com.google.android.gms.location.LocationClient instead. LocationClient provides improved location finding and power usage and is used by the "My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder for example example code, or the Location Developer Guide.
While it is great the new API appeared, I can't think of any good reason to put #Deprecated on these methods.
They are indeed a very convenient way of accessing location pointed to by the blue dot.
A single line
Location location = map.getMyLocation();
to retrieve my location vs the amount of setup code we need to write using the new Location API to achieve the same result speaks against having them deprecated.
From the MyLocationDemoActivity (under ANDROID_SDK/extras/google/google_play_services/samples/maps/src/com/example/mapdemo/MyLocationDemoActivity.java):
// These settings are the same as the settings for the map. They will in fact give you updates at
// the maximal rates currently possible.
private static final LocationRequest REQUEST = LocationRequest.create()
.setInterval(5000) // 5 seconds
.setFastestInterval(16) // 16ms = 60fps
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
The comment suggests that these hardcoded values are the same as in the map, but this may change in an undesirable way in future.
So after all the pros and cons are here, what could be the reason behind desision to deprecate these APIs?.
One more point. If GoogleMap uses LocationClient, but we don't have access to its results and we have to use another LocationClient and bunch of listeners, it is two LocationClients for the same task. Pure waste of resources.

Categories

Resources