Google Maps Api get lat long dynamically - java

I want to do something like aerophotography simulator as my university project, using Google Maps Api. For this, I need dynamically change viewport of a map, but for this I have to get lat and long of center of my viewport. Is there any way to do that, using Google Maps Api standart functions?

In order to get the coordinates (LatLng) associated with the center point (x,y) of the MapView you can use the method getCameraPosition().
(Assuming your GoogleMap object is mMap)
LatLng latLng = mMap.getCameraPosition().target;
In order to animate the camera position use the method animateCamera(), something like this:
mMap.animateCamera(location);
where location is the next location you wish to show on the map (LatLng object).

Related

Android - Get orientation (Compass like) where phone is pointing at

I have an array of Marker (google maps markers) with longitude and latitude.
I want to create some sort of radar like view that'll display these markers as points where I'm looking toward their directions with an angle of 45°.
Do you guys have any idea how I can say "This marker is behind me, this marker is in front of me".
I guess I should apply cos and sin considering my orientation, but that's too blurry atm.
Hope you'll help :)
Thanks
I assume you already know your location and orientation. You can then calculate the directions of the array of markers using computeHeading() method of Google maps Geometry Library on your current location and the points. Then you can adjust those values based on your current orientation.

creating a circular route from distance in android app

I would like to create a circular route from distance.
First, I get current position, and then create a circular route based on the specified distance.
But I don't know how to achieve this at all.
I couldn't find any helpful methods in Google Maps API.
Is there any way to achieve this?
You can do that easily as Android Google Maps provides that API.
GoogleMap map;
// ... get a map.
// Add a circle in Sydney
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(-33.87365, 151.20689))
.radius(10000)
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
Take a look at this official Doc.
The only change you need to make is to pass the current location's Lat/Lng to the center method.
You can follow this tutorial to get the current location coordinates of a person.

How to get Icon of Google Maps marker?

With marker.getTitle() you get the title of a marker, but how can I ask for the icon?
I want to ask if the icon of a marker is set to certain drawable and if so do something.
Well you can create marker with new MarkerOptions() Like this:
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.house_flag))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(41.889, -87.622)));
So you can simply store this data in some linked list or hash map
Without context on why you need the Icon, it is really hard to understand why you want it.
If you just want to move the marker or change the rotation you can do that by saving a variable for the Marker.
Marker allows .setPosition(LatLng) and .setRotation(Float).
Hope this helps someone since this is an old question

Display a location on Google Maps in Android Activity

I'm working on an Android project in which I will need to display the locations of various airports on Google Maps. I already have a list of latitude/longitude coordinates. My question is:
How do I get these coordinates to Display as a location in Google Maps on an Android Activity? What classes or other methods should I consider? Are there any templates or tutorials I could look at? Any help is most appreciated.
If you already have lat/lng for all required places, you can just use this in a loop for all coordinates:
LatLng loc = new LatLng(latitude,longitude);
map.addMarker(new MarkerOptions().position(loc).title("locationName"));
I think you need to use markers on your mapView
Here you can find the official documentation of the google map api, you'll find it's very easy to add marker on the map.
If you also need to use the current location, I suggest you to read This too.

How to get central point of Google Map?

I have been developing Android application and I can't make 1 thing - my application uses Google Maps (MapView), and one uses zoom elements for increase/decrease scale of Map. And I need to get center of Map - for example, I can move or increase the Map and than I need to get the central point. I know there is method setCenter() of MapController, but how can I get central point? Thank you.
mymapView.getCenter();
See this ....
http://android-er.blogspot.com/2009/11/mapview-to-center-on-current-location.html
public GeoPoint getMapCenter()
Returns the current center-point position of the map, as a GeoPoint (latitude and longitude).

Categories