Animate marker location to another in HEREMAPS - java

currently, i'm developing a map application similar to uber, and since im using Googles location service " intermitent thread " , i get the users location every 10-20-30 seconds and i update its new location on the map, by simply cleaning the existing List , and inserting another mark inside of it.
That makes it looks like the users icon is literally " teleporting " across the map.
ive made some researches and i was unable to find examples or of its possible to be done in Heremaps explorer edition.
I'm aware that all i gotta do is work with only one object instead of clearing my list and placing another object in it.
Any help would be appreciated, thanks in advance.

With the Explore Edition of the HERE SDK you can use the flyTo() method of the MapCamera. The speed and type of the animations between two distinctive coordinates can be heavily customized.
Just to give a simple example how you can move between two coordinates without "teleporting":
private void flyTo(GeoCoordinates geoCoordinates) {
GeoCoordinatesUpdate geoCoordinatesUpdate = new GeoCoordinatesUpdate(geoCoordinates);
double bowFactor = 1;
MapCameraAnimation animation =
MapCameraAnimationFactory.flyTo(geoCoordinatesUpdate, bowFactor, Duration.ofSeconds(3));
mapCamera.startAnimation(animation);
}
Whenever you set a new coordinate as target to the camera, it will instantly switch to that location - hence it looks like teleporting. With a linear (or bow like above) animation it will look smoother and in fact the coordinates between the previous and the new location are "interpolated".
With the Navigate Edition, there's also an InterpolationListener, which can be used to provide smooth interpolated location updates when a positioning source is used.

Related

How do you make Google Map have markers for several different places (such as gas stations)?

Im new to Android Dev but also knee deep in a project, just being held up by the APIs.
I am working on an Electric Vehicle app. It has an option to click a button (titled EV STATIONS) that takes you to a map. When you get to this map, it should have markers (which I want to be EV station drawable icons) on all EV stations in the direct area/city (I currently have it pointing to Atlanta).
I have the map set and loaded with an API key from Google console and all. The emulator runs and the map is of North America with a marker on Atlanta (where I want to focus it).
I would like for the map to be zoomed into the city of Atlanta, with all Electric Vehicle stations in Atlanta marked.
How do I do this? Is it possible?
When your app starts you can state where you want the camera and the zoom level with the following line.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultLocation, DEFAULT_ZOOM))
For the markers. I would suggest you make a class for these EV stations.
Everything on a GoogleMap is placed using a 'LatLng'. So it's best to have that datatype in your EVStation Class for ease of use. This class should also have at least a name, Id and LatLng. But you ideally would also store the address and other information you need for the app. The iD field is important, because when you click on marker, you'll location which EVStation it represents by their id's.
Once you have your EVStation Class. You'll have to find a way of importing this data. But just starting out, you can and write some temp data that gets initialed on app startup.
These EVStations that get loaded in will be put into an ArrayList<EVSTation>();
Once you have that arraylist, you can the loop through it to create markers on the map.
public static ArrayList<Marker> markEVStations(Context mContext,
GoogleMap map,
ArrayList<EVStation> eVStations)
//Create an empty array to store the markers.
{ ArrayList<Marker> allEVStationMarkers = new ArrayList<>();
//Loop throw the EVStations, createing a marker for them and adding that marker to allEVStationMarkers arraylist
for (EVStation e : eVStations) {
Marker evStationMarker = map.addMarker(new MarkerOptions()
.position(e.getLatLng())
.title(e.getName())
.icon(YOUREVSTATIONICON)
.draggable(false));
evStationMarker.setTag(e.getId());
allEVStationMarkers.add(evStationMarker);
}
return allObservationMarkers;
}
Just running the above method will put markers on the map. The ArrayList it returns isn't needed, but it makes it easier to use the markers individually once they've been created.
If you need more help with this project. I suggest just sitting down and breaking it up into a bunch of features (This is what the professions do). Then address each feature one at a time. Because right now, your question is very broad, and you provided no code. It's hard to give you a technical answer. My code example, may not fit your intended solution.
Good luck!

Is it possible to add childs while keeping old ones using Firebase databse in Android Studio?

I am saving coordinates from a list in Firebase using smartphone sensors. The X is being saved on a child called "Coordinate X" and Y on a child called "Coordinate Y". Both of these child are inside a child called "Path 1".
What I want is: everytime I run the app to add coordinates but in another child with the same name, like this -->
How it really is:
enter image description here
How I want it:
enter image description here
Right now, every time I run the app it overwrites the childs coordinates X and Y. Every time I run the app I want to add two more child "Coordinate X" and "Coordinate Y" with the new coordinates.
I tried using push() but it is hard to understand what is the new data and old data and it really didn't split the coordinates per app run.
I am sorry if I didn't explain well. Thank you!
Keys are by definition unique within their parent, so you can't have multiple child nodes named Coordinate X under a single parent.
The idiomatic approach for this is to create a list of uniquely named child nodes, by calling push for every set of coordinates.
If you're using the Android SDK (given that you tagged with Android), that'd be:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Path 1");
Map coordinates = new HashMap();
coordinates.put("X", 123);
coordinates.puth("Y", 456);
ref.push().setValue(coordinates);
Also see the Firebase documentation on reading and writing lists of data.

how to restrict maps to only one country using google maps api for android

I am totally new to google's maps api for android and I was wondering if it is possible to restrict the area the map is showing to one country only. I mean my target users are in my own country only and it is not useful nor logical to show them the whole world when the application logic is going to be only on this country.
Any ideas?
ps: if it is not possible in google's api,is there a way to do this with another api form another source which provides a mapping service?
If you are still interested, now it's possible to restrict the user's panning to a given area using the setLatLngBoundsForCameraTarget method.
You will need to update the dependencies for your Play Services:
dependencies {
compile 'com.google.android.gms:play-services:9.6.1'
}
You can restrict the user view to specific square -maybe- of the map, to do so, you can use the following:
private GoogleMap mMap;
// Create a LatLngBounds that includes the city of Adelaide in Australia.
private LatLngBounds ADELAIDE = new LatLngBounds(
new LatLng(-35.0, 138.58), new LatLng(-34.9, 138.61));
// Constrain the camera target to the Adelaide bounds.
mMap.setLatLngBoundsForCameraTarget(ADELAIDE);
in this case, the user will not be able to zoom in, in the map in areas where the camera is totally out of the range -square- you specified.
for more details, source: https://developers.google.com/maps/documentation/android-api/views#restricting_the_users_panning_to_a_given_area
I am pretty sure you cannot only display your chosen country using the google api service. However, what you can do, is restrict google places auto complete to a specific country, by finding your country code (e.g. using this link https://countrycode.org/) and then adding the query to your google places api e.g.
components=country:your_country_code //Insert code into example
For example, this is what is would look like:
https://maps.googleapis.com/maps/api/place/autocomplete/json?
input=bhubaneshwar&components=country:in&sensor=false&key=your_key
out of the box this is not possible. However what you could theoretically do it find the max bounding box that shows the country in question then everytime the camera moves check to make sure the bounding box is inside the max one. If it is not set it to the max. that would restrict them to a certain spot
you can override the map and specific the latitude and longitude
and zoom in with suitable for you and disable the gesture of map
see this example it is answered before
limit scrolling and zooming Google Maps Android API v2

Adding 5900+ markers to Google Maps on Android. How to do efficiently

I am creating an app that uses Google Maps to show locations of stores. I have an array of 5900+ locations that I would like to have on the map. I am currently using https://github.com/MadsFrandsen/MapStateListener to make markers in a location visible and hide all other markers that are not in the screen range.
However the problem is mainly how loading 5900 markers onto the map on initialization takes quite a few seconds and reduces the devices speed and I keep retrieving errors about skipped frames.
What methods do I have that will best allow me to have these locations available when a user scrolls from state to state (as I load 50KM away from initial device location) ?
I don't think any user will find a visual filled with 5900+ markers useful.
There's no way to make this problem go faster unless you can figure out a meaningful way to display less data. You need to filter those locations better. Maybe only displaying those stores within a 10 mile radius of the current GPS location would work better. It'll render faster, and your users will thank you for not confusing them.
I pretty much doubt you need to display all 6k markers on your map at once as your view will get rather crowdy. However if you really think that makes sense, there's library that you may find useful -> Android Maps Extensions
demo: https://play.google.com/store/apps/details?id=pl.mg6.android.maps.extensions.demo
code: https://www.google.com/url?q=https://github.com/mg6maciej/android-maps-extensions/&sa=D&usg=AFQjCNEnOeOZB4NbvpjQldmChbVbzCZV7Q
First, you should group your markers into one if they are too close to each other when user zooms out. Then you should update your map only if user stops scrolling, zooming. It will take you a possibility to make UI faster.
You should add so many markers on map so user can see on the screen

I can't add more than one line (overlay) to Android google-map?

I'm having problems with adding lines to the map in my android project. Basically, when I want to draw lines from point A to point B android is painting them just fine, but when I want to add another line later (say from point B to point C) android is removing the old line and drawing a new one. I guess it has something to do with collections because I'm using the ItemizedOverlay class to collect all markers and it seems to work, but how to do the same with lines or anything else I would like to draw? How to prevent android from refreshing the map? ItemizedOverlays seems to do the trick, but only with markers/drawables. Can someone please give me some help or at least point me in the right direction with this? I would greatly appreciate it.
I have one class witch extends from Overlay that draws a line between X points in the draw method. i'have a for loop that creates one LineOverlay each time and adds it to mapView.getOverlays() with no problem.
If you want to remove one determined overlay you have to store somewhere in the class when you create them to call later to mapView.getOverlays().remove(LineOverlay item)
Hope i helped you.
See my reply with code samples at How to draw a path on a map using kml file?, it describes how to draw routes (consisting of multiple lines).
Especially look at the Drawing / drawPath() section.

Categories

Resources