Google Maps How do I get the current CameraLocation object? - android

When I close my map or switch a different activity, the map calls the onSaveInstanseState(). I want to get the current camera position and LatLng so that when the user switches back to the map, they will be in the same location.
Thank you.

Google Maps have a getCameraPosition() method.
To get the latLang, you simple have to get the camera position then get the target. Such as:
LatLang latlang = googleMaps.getCameraPosition().target

Related

Is there a way to determine a user's current map view area?

Is there a way to determine a user's current map view area, whether in Google or Apple Map?
I'm in the process of designing a geolocation app, and want to show the names of locations near the user. I could use distance from user as the parameter, but want to see if there's a way to only show the names in the current map area that's being viewed instead. I've done a decent search but haven't found any method.
Thanks!
There's an object called VisibleRegion in the GoogleMap that gives you this information (Google Maps V2 for Android). You get this from the GoogleMap object with the following code
VisibleRegion region = getMap().getProjection().getVisibleRegion();
I called getMap() to get the GoogleMap object because I was in the context of a MapFragment...not sure what your implementation is.
http://developer.android.com/reference/com/google/android/gms/maps/model/VisibleRegion.html

Finding the shortest route from current location to the locations marked on a map

I have mapped my current location and also 4 other locations on my map.Is it possible the mark the route which is closest to the current location(1),then from that(1) to the next closest(2) position,then so on(3).!!Finally i should have the route from my current location marker via all the location in between(markers) till the last marker!!
Thanks in advance!!
You are going to have to use separate instance of DirectionsService object to make your directions request for each destination and then set that to the map using the same instance of the DirectionsRenderer object.
Take a look at this JSFiddle
There are three separate directions in this example. Just make the start the same location.

How to simulate Google maps Marker inheritance on Android

I would like to simulate an inheritance of Marker from Google Maps API V2. I know it's impossible to inherit from Marker because Marker is a final class and that's my problem.
My final goal: create a Marker (let's call this one MainPoint) which deploys 5 others Marker (let's call them Petal) when I click on it and hides them when I click again.
When Petals are deployed around MainPoint, thanks to onMarkerClickListener I can catch the marker but I can't identify if this marker is a MainPoint or a Petal.
If I could make Petal and MainPoint inherit from Marker or even put a tag on it, I would just have to check if this is a Petal or a MainPoint to know which method I have to call but with only the instance of a Marker, the only way I found is to check every instance of every MainPoint and its Petals if it's equal to the marker clicked.
I hope you can help me to find a way to design this situation.
I can't identify if this marker is a MainPoint or a Petal
Maintain a HashMap mapping petal Marker IDs to main point Marker IDs. Look up your Marker in the HashMap to find its associated main point, and if you get back null, you know that it is a main point.

Android maps V2 Driving instructions in textview

Im developing a map app in which gps detects my current location and places a marker.Using spinner I get nearby places based on category.What I need is,When I longclick the marker of spinner,Using intent it should show the step by Step navigation instructions in a new page also it should draw route ie polyline from my location to the touched location.
I used http://wptrafficanalyzer.in/blog/showing-nearby-places-and-place-details-using-google-places-api-and-google-maps-android-api-v2/ code for abvove purpose.
Please Help..Thanks in advance.
You can take a look at this blog post I wrote on drawing the navigation on the map:
Google Maps V2 for Android: Draw Driving Direction on Map
For adding the Step by Step navigation I guess you would need to change the parsing method a bit in order to get this info from the JSON file you receive.

How to speed up myLocation determination

I am using the new API V2, but that's probably not important since I am newbie for maps anyway:)
I have very simple need. I want to show my location and one target marker and all is working. It's just that the my location determination is not predictable, can get minutes or so to get the blue circle.
What I thought is to manually use the LocationManager to retreive in background the coarse or fine location and pass that value to the Mapactivity. Since normally the map activity will not start immediatelly it would work nice. Then I could also save to databse the last location and pass that in the case the map activity starts before the LocationManager get the real location.
I am looking at the api's but could not find a function that would display imemdiatelly the blue circle at given LatLong. Is this function available?
If this function is not available the only workaround that I could find is to override onlocationchanged to retrieve the new location and save the last, and to display the marker on last known mylocation (that would hide automatically itself on first locationchanged event).
But it would be easier, and also pretier, if I could simply pass initial mylocaltion coordiantes?
Thanks for any idea
I am looking at the api's but could not find a function that would display imemdiatelly the blue circle at given LatLong. Is this function available?
Use setLocationSource() to provide a LocationSource to the GoogleMap. Once your LocationSource is called with activate(), you will be handed a listener object, to which you can pass Location objects for the readings you get from a location provider.

Categories

Resources