Show a moving bus in google maps api v2 android - android

I am trying to show the position of a moving bus in google maps api v2 in an android application. I am able to mark the stops and draw routes using the markers and polylines. Now, I am trying to have an image(bus/Marker) that moves along the route that is there in the map. I am using GroundOverlay to achieve this, but I am not able to re draw the moving image/marker using GroundOverlay.
The problem I am facing is that, as I am drawing the map in the OnCreate function, the map, markers, routes and all the positions of the moving marker are displayed only once at the end of the oncreate function. I think I am going in the wrong direction. Is there a way to redraw only the moving marker? Is it possible to have a view on top of a map and draw on the view using projection? (is this possible in V2? If Yes, do we have some demo or sample available online?)

Related

How to know if markers on the map touch each other

I am building an application which uses Google Maps. When displaying the map, I'm also adding markers. Is there a way to see if there are 2 markers that touch each other, meaning if a part of a marker is on top of another marker? My goal is to be able to find that out and then make them a single bigger marker instead of 2 different markers.
The answer should depend somehow on the marker's icon size and the current map zoom since if I zoom out, there's a bigger chance they might overlap.
There seem to be a library made by Google which clusters a set of markers together automatically when they are close to one another.
The library is the marker clustering utility and instruction can be found here:
https://developers.google.com/maps/documentation/android-api/utility/marker-clustering

Drawing on the MapFragment, while keeping some elements visible

I'm developing an application that has the following goal:
Using the google maps android API 2 I get my current position, and as I start walking the application starts drawing the route I take
The twist is that the map is a "blind" map. Meaning the map is hidden, only the Marker of my current position and a dotted line of my route is shown.
Keep in mind I'm a novice developing to Android, so please be specific. (Thank you)
I managed to create the map, get my current position and zoom in to it (Had no sens to see the whole planet while i want only my current position). And it's pretty accurate so far.
The thing is I don't know what should I do from this point on.
Basicly I need a white View between the Marker and the real map. Also as I advance that View should always be on, over the MapFragment/MapView. Also I wish to keep the zoom and drag functionality's of the MapFragment.
How can I achieve this?
At this point I'm opened to any solutions.
(Been browsing for a few days now the developers site, I have seen that with the ViewOverlay class I can put messages over the map, but I'm not sure what would the correct aproach be in my case...)
To hide the whole map behind the white view I would use Polygon class Polygon Even if you specify Polygon to cover the whole map Markers will be still displayed in front of it and as so user's current position marker will be visible. You also will be able to zoom and drag.
To draw line on map use Polyline class Polyline It will draw users path as a polyline. If you want to stick with dotted line you can use Circle objects to create it. Circle

Custom drawing in Google Maps Android API v2 (curved Polyline)

I have a MapView (provided by Google Maps Android API v2) and what I'm trying to achieve should be simple enough, which is simply to draw a curved Polyline.
To be specific, I have an array of LatLngs and rather than having them joined at sharp angles, I want to have the route rounded off nicely, so that the line through the points follows a curve rather than straight lines and sharp angles.
Now, this used to be possible in the old Google Maps API by creating a custom Overlay, overriding draw(), and then manually drawing onto the map (e.g. with a custom Paint and Path with the desired settings).
Unfortunately it seems that in v2, Google have removed the Overlay class and moved to higher-level abstractions which no longer provide access to the draw() method. PolylineOptions is fairly basic and doesn't provide any option to draw a curved line.
Is there any way to override draw() or use other features of Google Maps API v2 in order to draw a curved Polyline?
There are a few questions already on SO which cover this issue, however there isn't really a satisfactory answer as yet:
Custom Overlays in Google Maps API v2
Overrinding draw() in customized MapView in Google Maps Android API v2
I'm sure there must be a way to do custom drawing on Google Maps v2, and whilst creating a custom overlay View and drawing onto that once the coordinates are synced up with the map is an option, it will quickly get extremely complicated when dealing with scaling and panning the map, so it's something I want to avoid if at all possible.
I have developed an abstract class CanvasTileProvider() where you just have to override the onDraw method, in order to perform your drawing as usual into a Canvas. A TileProjection object, which is passed into the onDraw method in addition, helps you to do the back and forth calculation between LatLng and points on the Canvas.
The only limitation is, that tiles are usually loaded only once. So this way of drawing into the map is suitable for shapes which do not frequently change. Thus it may not be suitable if your array of LatLng objects is continuously changing (e.g. because it shows the current movement of the device).
You can find the CanvasTileProvider class in the answer to this SO question

Arrows on map with google maps API

I am using the google maps api for an android game that incorporates the players movement in the real world. I have figured out how to make markers indicating where something would be on the map, but I would like to keep a fixed map zoom level and have off-screen markers show up as arrows on the screen.
Anyone know of a way inside of the map API to do this without having to explicitly figuring out the angle to the object and rotating an arrow icon to point in that direction.
I don't have experience of the Google API, but from a simple point of view if you know the current location and the marker location couldn't you just use some simple vector maths to calculate the heading and, therefore, the arrow heading?
i.e.
MarkerPosition - CurrentPosition = TargetVector
TargetVector.normalize()

Google Map API, with my own created Map figure

In android, is it possible that I would create my own Map figure, and then use this Map with the gps location from Google Map API
Example, I draw a map for my own house, then apply Google Map API to be able to make the location of each point in the map
Yes, I believe you can. A couple of options are as follows:
Draw your 'map figure' in an overlay - if the background is translucent, then you'll be able to see the Google map underneath.
Alternatively, use a dummy Google maps API key - in this case the MapView layer is rendered as a grey background but all the API calls appear to work. Again render your 'map figure' in the Overlay draw method.
In both cases, you'll have to ensure the map projection (scale, position, etc) match up with the coordinates of your 'map figure', especially if you scroll or zoom the map view.
It might be best going with the first option, initially, then you'll have a visual confirmation if you're code is correct.

Categories

Resources