Map view set according to distance - android

I am a new android developer. I am creating a map view application Where I want to set up my map view according distance from my current location. I have three buttons such as 100m,500m and 1 Km . When application is started then mapview will appear and current location is the center of the map. When i tap on 1 km then the map view is set up 1 km according to current location. How can i do this.Thanks in advance.

You have to compute 1km in latitude and longitude, set the center to your current position ( I guess you succed to do that) and set the span to your MapController:
mController.zoomToSpan((int) spanLat,(int) spanLon);
zoomToSpan
public void zoomToSpan(int latSpanE6,int lonSpanE6)
Attempts to adjust the zoom of the map
so that the given span of latitude and
longitude will be displayed. Because
the zoom can only achieve discrete
levels, and because the aspect ratio
of the map may not match the ratio
given, the quality of the fit may
vary. The only thing we guarantee is
that, after the zoom, at least one of
the new latitude or the new longitude
will be within a factor of 2 from the
corresponding parameter.

Related

How to put marker at bottom of map instead of center(by default) of map with zoom enabled in android?

In live track app I want to animate camera above marker and want to put marker always at bottom in newLocationChanged.
If I am building CameraPosition without zoom, It works fine.
But with zoom also I need to achieve same.
Use the screen boundaries to get the desired position:
As per documentation:
getBounds()
Return Value: LatLngBounds
Returns the lat/lng bounds of the current viewport. If more than one copy of the world is visible, the bounds range in longitude from -180 to 180 degrees inclusive. If the map is not yet initialized (i.e. the mapType is still null), or center and zoom have not been set then the result is null or undefined.

Attain maximum zoom on google map showing all markers

i have 5 markers to display on the map, out of which 4 are very near to each other and the fifth one is a little bit distant to these 4. now when i display the map i want all these 5 markers to be shown on map and the with the highest possible zoom. i dont care whether they are on the border of the screen or in the center of the screen.i mean the markers can be scattered on the screen but all i want is that all markers should visible to the user and with the highest possible zoom.
i have tried this Android map v2 zoom to show all the markers . but the result is that it is showing all markers at the center of the map with very little zoom. actually i have calculated screen dimensions using this code.
DisplayMetrics metrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float height=metrics.heightPixels/metrics.xdpi;
float width=metrics.widthPixels/metrics.ydpi;
but i dont know why there is very little zoom. But wen i saw android documentation, i think the function is doing justice by doing whatever it said it will do.
public static CameraUpdate newLatLngBounds (LatLngBounds bounds, int width, int height, int padding)
Returns a CameraUpdate that transforms the camera such that the specified
latitude/longitude bounds are centered on screen within a bounding box of specified
dimensions at the greatest possible zoom level. You can specify additional padding,
to further restrict the size of the bounding box. The returned CameraUpdate has a
bearing of 0 and a tilt of 0.
Unlike newLatLngBounds(LatLngBounds, int), you can use the CameraUpdate returned by
this method to change the camera prior to the map's the layout phase, because the
arguments specify the desired size of the bounding box.
as it says it keeps all the markers at the center of the map. i do not want that. i want all the markers visible to the user with the maximum possible zoom and markers scattered. can anybody please help me?
Your calculation of float width and height is incorrect.
What your width holds now is inches (value of approx. 2 on phones). You need not to divide pixels width.

Setting view on mapview based on gps coordinates

I'm trying to set the bounds on the mapview that I'm working with, so I'm always centered a certain way, and I can also see a full set of information based on the view. Basically I'll get a GPS coordinate for the center point, and then I'll get another value, say .9, which is the difference in the x/y of the current GPS spot that needs to be present in the current view. Example
Center-point: 37.777125, -12.2419644 (San Francisco)
Difference: .9
So the view would need to be
Top-Left: 36.877125, -13.1419644
Bottom-Right: 38.677125, -11.3419644
Is there a way to set the map view's bounds in this way?
It is. There is an interface in mapView's controller - zoomToSpan(long, long).
What you need is to do the following:
long latSpan = Math.abs(startLat - endLat);
long lonSpan = Math.abs(startLon - endLon);
mapView.getController().zoomToSpan(latSpan, lonSpan);
Where startLat, endLat, startLon, endLon - your calculated boundaries

Android Map Zoom Level for Current Location and Destination

I am displaying the user's current position and their intended destination using Google maps, MappingOverlayActivity and ItemizedOverlay.
What is the best way to firstly set the appropriate zoom level so that both locations are displayed on the map on the screen with the maximum area covered by the map, i.e rather than the current location being in the centre, having the centre being in the middle of the 2 points.. Also when the user's current location changes, how can I then recalulate and reset the appropriate zoom level to incorporate the new current location.
You use methods from MapController (which you obtain using mapView.getController()).
Specifically animateTo (or moveTo), and zoomToSpan.
Assuming you have two GeoPoints
GeoPoint current;
GeoPoint destination;
do something like this
mapController.zoomToSpan(Math.abs(current.getLatitudeE6() - destination.getLatitudeE6()), Math.abs(current.getLongitudeE6() - destination.getLongitudeE6());
mapController.animateTo(new GeoPoint((current.getLatitudeE6() + destination.getLatitudeE6())/2, (current.getLongitudeE6() + destination.getLongitudeE6())/2));
so you calculate the span (difference) and center (average) of the points.
For the center of the coordinates you might need to do some math
http://en.wikipedia.org/wiki/Centroid

i want to draw circle around my current location excatly 1 kilometers readius

hi friends i want to draw circle around my current location exactly 1 kilometer radius so wat can i do.....i able to draw circle but how to put radius so it becomes exactly one kilometer..
At a high level:
Get the bounding coordinates of your current map view.
Use your coordinates to compute the distance either horizontally or vertically across your map. Convert your distance to meters, if necessary.
Divide your distance in meters by the horizontal or vertical resolution (in pixels) of your map view. This gives you the number of meters per pixel at your current zoom level.
Evaluate 1000 / <meters per pixel> to determine the number of pixels in 1 kilometer at the current zoom level. This is the radius of your circle.
Draw your circle using the radius you got in step 4.

Categories

Resources