how can i add different overlays at different zoom levels ? For instance i have an overlay image of a festival area that ive added onto the map which is great. But when the user zooms out i want to change the image that the user see's .Does anyone know how to do this?
The only thing that I can think of is to pass the zoom level into the overlay when it changes in the map and then make the decision on what to draw in the overlay.
I was having same problem but what you can do is define the size of bitmap based on difference of two geopoints e.g.
GeoPoint PointC = new GeoPoint((int)(35.496392 * 1E6), (int)(-97.5375950 * 1E6));
GeoPoint PointR = new GeoPoint((int)(35.496392 * 1E6), (int)(-97.5362690 * 1E6));
GeoPoint PointH = new GeoPoint((int)(35.696392 * 1E6), (int)(-97.5362690 * 1E6));
Point poC = new Point();
Point poR = new Point();
Point poH = new Point();
projection.toPixels(ovalR, poR);
projection.toPixels(ovalC, poC);
projection.toPixels(ovalH, poH);
cWidth = Math.abs(poC.x-poR.x);
cHieght = Math.abs(poC.y-poH.y);
Bitmap bitmap= Bitmap.createScaledBitmap(mBitmap, cWidth, cHeight, true);
If you control the zoom buttons (by having your own buttons), you may simply change the displayed overlays by modifying the array mapView.getOverlays() and then call mapView.invalidate().
I didn't try to change it so frequently but it should probably work.
Related
Good afternoon,
When i'm starting my application, the mapview is showed like you can see in the follow picture :
but i would like to start the mapview with some zoom in some point, something similar to this :
Which method i need to use?
Thanks in advance.
You add a zoom level to the map controller:
mapView.getController().setZoom(17); // an int that suits you
Read more about zoom levels here: https://developers.google.com/maps/documentation/staticmaps/#Zoomlevels
To set center you can use:
mapView.getController().setCenter(new GeoPoint(latitude,longitude));
set -
mapView.setStreetView(true);
mapView.getController().setZoom(17); // an int that suits you
mapView.getController().setCenter(new GeoPoint(latitude,longitude));
This is the solution.
for displaying egypt use it-
String coordinates[] = {"18.352566007", "73.78921587"};//here you can set geopoints of egypt
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));//p is GeoPoint
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
In my application i have multiply overlays over the map.
In each overlay's draw() method i draw shape using points from list.
final int listSize = list.size();
for (int i = 0; i < listSize; i++) {
mMapView.getProjection().toPixels(
new GeoPoint((int) (list.get(i).getPNT_LATITUDE() * 1e6), (int) (list.get(i).getPNT_LONGITUDE() * 1e6)), point);
As you can see, i have to create GeoPoint object each cycle to get pixel projection.
I can't creat single object and use it every time, because GeoPoint has no "set" methods.
Is there any way to get projection without creating GeoPoint?
no, unfortunately not. i would almost pay for this functionality ;)
many map things around GeoPoints and the Projection are very buggy and the classes are all final and no source code to be found
if your coordinates somehow repeat themselves, you could store the geopoint.
I have a Data Structure (ada) that stores lat/long, title and drawable for each marker. There are many markers (~500) and i would like to show the markers only on the currently viewable area. (The relevant code is posted below.)
for (int i = 0; i < ada.size(); i++) {
GeoPoint point = new GeoPoint(
(int) (Float.parseFloat(ada.get(i).latitude) * 1E6),
(int) (Float.parseFloat(ada.get(i).longitude) * 1E6));
Drawable d = new BitmapDrawable(ic.get(ada.get(i).brand_front_thumbnail));
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
OverlayItem overlayitem = new OverlayItem(
point, ada.get(i).title);
overlayitem.setMarker(d);
itemizedOverlay.addOverlay(overlayitem);
}
I can check if the geopoint is within screen coordinates and set drawable only if it is inside, but how do i update the map when the map is moved?
I have a Data Structure (ada) that stores lat/long, title and drawable for each marker. There are many markers (~500) and i would like to show the markers only on the currently viewable area. (The relevant code is posted below.)
for (int i = 0; i < ada.size(); i++) {
GeoPoint point = new GeoPoint(
(int) (Float.parseFloat(ada.get(i).latitude) * 1E6),
(int) (Float.parseFloat(ada.get(i).longitude) * 1E6));
Drawable d = new BitmapDrawable(ic.get(ada.get(i).brand_front_thumbnail));
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
OverlayItem overlayitem = new OverlayItem(
point, ada.get(i).title);
overlayitem.setMarker(d);
itemizedOverlay.addOverlay(overlayitem);
}
I can check if the geopoint is within screen coordinates and set drawable only if it is inside, but how do i update the map when the map is moved?
I have two geo points that vary intermittently, and want the MapView to resize and translate to make sure both points are always visible. I can easily re-centre the map on the point mid-way between the two, but how do I set the zoom level to ensure my two points are visible?
Check out his answer in a different post:
Google Map V2 how to set ZoomToSpan?
It solves it without much hassle. Note that you can only use that function AFTER the map has been loaded at least once. If not use function with specified map size on screen
LatLngBounds bounds = new LatLngBounds.Builder()
.include(new LatLng(CURRENTSTOP.latitude, CURRENTSTOP.longitude))
.include(new LatLng(MYPOSITION.latitude, MYPOSITION.longitude)).build();
Point displaySize = new Point();
getWindowManager().getDefaultDisplay().getSize(displaySize);
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, displaySize.x, 250, 30));
Works like a charm and very dynamic!
Try this and see:
double latitudeSpan = Math.round(Math.abs(firstLat -
secLat));
double longitudeSpan = Math.round(Math.abs(firstLong -
secLong));
double currentLatitudeSpan = (double)mapView.getLatitudeSpan();
double currentLongitudeSpan = (double)mapView.getLongitudeSpan();
double ratio = currentLongitudeSpan/currentLatitudeSpan;
if(longitudeSpan < (double)(latitudeSpan+2E7) * ratio){
longitudeSpan = ((double)(latitudeSpan+2E7) * ratio);
}
mapController.zoomToSpan((int)(latitudeSpan*2), (int)(longitudeSpan*2));
mapView.invalidate();
in the new Maps API (v2) you can do it this way:
LatLng southwest = new LatLng(Math.min(laglng1.latitude, laglng2.latitude), Math.min(laglng1.longitude, laglng2.longitude));
LatLng northeast = new LatLng(Math.max(laglng1.latitude, laglng2.latitude), Math.max(laglng1.longitude, laglng2.longitude));
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(southwest, northeast),500,500, 0));