GoogleMap.OnCameraIdleListener Mapbox equivalent - android

I am looking for an GoogleMap.OnCameraIdleListener equivalent in the Mapbox Android SDK.
Usecase
When panning around the map I need to query some geojson from a server, which is to be shown on the map.
For this I need to be able to detect when the map have moved and is once again idle. Google Maps have the OnCameraIdleListener and OpenLayers have the 'moveend' event. I can't use Google Maps due to some licensing issues and I'm trying to find a native alternative to OpenLayers, which I currently use.
What I have tried
I have tried to use various listeners offered by the MapboxMap class, but all of them is called much too often. Like the following:
map.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition position) {
Log.d("TAG", map.getProjection().getVisibleRegion().latLngBounds.toString());
}
});
The method is called a lot of times (every 400ms I think during panning). If I were to use the method directly the server load would be much too large as well as handling the returned data.
I could make a workaround that only calls the server if no CameraChange event has occurred for 5-800ms, but it would result in some not-to-nice code.
Possible duplicates
I found the following in the MapBox github:
https://github.com/mapbox/mapbox-gl-native/issues/4746
The issue seem very similar. I have tried the proposed solutions, but without a satisfying result.
Have I missed some implementation or does someone know of a nice workaround?
Thanks in advance.

Functionality added in v5.1.0
https://github.com/mapbox/mapbox-gl-native/pull/8644

Related

SnapRoads - how to?

I've implemented a Google Location Api on my app to track my routes. I record my coordinates in a sqlite Db and then save these coordinates as a GPX file to see on map parsing and build via polylines.
There are a lot of points.
I see that unfortunately the position not seems follows the road even if I drive/walk in the middle of it.
Searching with google I've founded SnapToRoads as part of Google map API but, unfortunately not for Android, even if it seems that is possible to implements (but I don't know in which manner).
I wonder if someone knows how to solve this problem or some workarounds
At the end, I implemented SnapToRoad API to solve this problem, even if I have to use my key on source code (if I don't want implement a web site with Javascript)

MapBox Find terrain class by coordinates in Android

I spent several hours looking for simple solution and still haven't found one.
MapBox style editor uses this simple feature. That you can hover and click over map, and it shows small popup stating all terrain classes you enabled in your map.
Question, how to do it in Android version of MapBox given I have installed my style. Now I want click on any place in the map and get the same popup stating, for example, that this is building, woods, background here. Or other place would satte, that this is major road.
This IS doable as MapBox studio itself shows. i can't believe it uses some API not available for anyone, as this is one API no map provider gives, while still able correctly draw terrain. What so complex to add this API?
And NO I am not interested in address. I am interested exactly on terrain, for simple task - distinguiosh water from non-water, road from non-road, building, from non-building, don't care where it is by address, so reverse geolocation does not work. Or simpler - I need SIMPLER geolocation, than address.
Your questions kind of confusing but I'll try and help. If I'm reading correctly, you are trying to create an Android app that uses an API similar to Mapbox Studio that allows the user to select/distinguish the difference between objects on the map such as buildings, water, forest, etc.
If this is the case, then first you must understand that Mapbox Studio is using OpenStreetMap data to distinguish between objects. These objects are stored in a database with tags. It's tough to explain so i'll just leave a brief reading wiki page that might help.
To my knowledge, there isn't any API's specific to Android that will give you the kind of information you're looking for. However, if I was in your dilemma I'd take a look at the Overpass API as it's a complex query tool that allows you to send coordinates to it and it will return all the tags (such as building or water) at that location within a JSON object. From there you can parse and use the data in your app. It is very powerful so I suggest reading up on how to use it and test using a website called Overpass Turbo, that's if you decide to use it.
Nevertheless, I hope this helps and I understood your question correctly.

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 Google Places API with updated Google maps v2

Over the past few days, I am trying to find a step - by - step tutorial to implement google places with the updated version of google maps (in eclipse for Android) with no success.
In the old tutorials I find , the map doesn't appear, because it is not updated in the v2.
Can anyone suggest a way to proceed? I feel lost with all the scattered information I get, and I don't have the experience to change the old examples by myself.
I want to make a simple app, that finds my current location and displays the cafes and restaurants, within 3Km distance. At this point I have tha map showing my location, and I need a tutorial to guide me into implementing Google Places from scratch.
Please help!
I'm actually making an app quite similar to yours! I haven't updated to v2 yet but from what I can tell, the only major difference in implementation is the use of a MapFragment as opposed to a MapActivity.
So you have the map up, yes? Then you should be able to make calls to Google Places the same way you did with the v1 Maps (since they're separate components and don't depend on each other). If Places is what's giving you trouble, I suggest following this tutorial: http://ddewaele.blogspot.com/2011/05/introducing-google-places-api.html. It's pretty good and only needs a couple of tweaks to get things up and running.
If you're still having trouble, post back and I might be able to help you out with some code.
i found this post helpful,i hope you will find it too,
http://mobile.tutsplus.com/tutorials/android/android-sdk-working-with-google-maps-map-setup/

How to catch a map panning | zooming finished event with Android SDK?

I am looking for a way to receive events when a map finished panning or zooming or panning and zooming. Those events are not fired, afaik, from MapActivity in the SDK for Android 2.3.3 which I use. I tried the MapChange library, however, it forces you to use Handler in your MapActivity to ensure to that UI updates are processed on the UI thread; more information.
Question: Do you know of any support for such events by the Android Support Library e.g. by using FragmentActivity instead of MapActivity - I could not find an alternative solution by now.
Similar questions can be found here:
Android MapActivity on map movement
How to catch that map panning and zoom are really finished?
Edit:
The MapChange library was updated some hours ago. I will check out what has been improved.
Edit:
The MapChange library has been improved and works much more reliable now and is a good option! Please checkout the GitHub project for further information. However, I leave the question open since I am still interested whether one can do the same with existing components.
You can use the GoogleMap.OnCameraChangeListener to assign a listener to the changing camera event. Handling that and other events is discussed in the Google Maps Android API documentation.
Why is it a problem to use a Handler ? You can always post your UI changes to the main thread, why not do that ?
Someone on SO found a way to get a Fragment activity to contain a MapView by changing the support library code but it became too cumbersome for me to use and I reverted to a full-blown Map activity.
For anyone still looking for an answer to this
googleMap.setOnCameraIdleListener {
//Do your thing
}
called when camera movement has ended

Categories

Resources