Been wanting to display just one section of the world map. Made mbtiles for it as well. But I also want the user to not be able to move outside a limited area. Below is the code I ran using Bounding Box on the world map but nothing is displayed on the screen, both on an emulator and an actual android device. Please help.
IMapController mapController = mapView.getController();
BoundingBox bounds = mapView.getBoundingBox();
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setUseDataConnection(false);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapController.setZoom(10.0);
mapView.setMinZoomLevel(10.0);
mapController.setCenter(new GeoPoint(51.459569,-0.167153));
//compass
CompassOverlay mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this), mapView);
mCompassOverlay.enableCompass();
mapView.getOverlays().add(mCompassOverlay);
//scale
ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(mapView);
mScaleBarOverlay.setCentred(true);
mScaleBarOverlay.setScaleBarOffset(500, 50);
mapView.getOverlays().add(mScaleBarOverlay);
mapView.setScrollableAreaLimitDouble(bounds);
Related
Hi everyone I'm using osmdroid in my application. I have a list of Latitude and Longitude sets and want to show them on the map and each one should be clickable means when I click on one of them it opens new specific activity. so how i suppose to do that ?
I want to do something just like this :
Sadly i couldn't find much information about working with osmdroid so any help would be appreciated.
This is how i used osmdroid map
mapView.setTileSource(TileSourceFactory.MAPNIK);
IMapController mapController = mapView.getController();
mapController.setZoom(9.5);
GeoPoint startPoint = new GeoPoint(34.796830, 48.514820);
mapController.setCenter(startPoint);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
And this is overlays with geopoints :
List<OverlayItem> mItem = new ArrayList<OverlayItem>();
Drawable mMarker = this.getResources().getDrawable(R.drawable.marker_default);
GeoPoint point;
if (nearestDiscountsList.size()>0) {
for (int i = 0; i < nearestDiscountsList.size(); i++) {
point = new
GeoPoint(Double.parseDouble(nearestDiscountsList.get(i).getLatitude()),
Double.parseDouble(nearestDiscountsList.get(i).getLongitude()));
OverlayItem overlayItem = new OverlayItem("Here",
"sampleDescription", point);
overlayItem.setMarker(mMarker);
mItem.add(overlayItem);
}
}
But I do not know where to add these ):
Even any sample code about this will do the job.
Well.
i have an irritating problem and i dont know how to fix it !!
When i get the lat and lng form gps. The map shows 2 markers ( one icon by default and another icon customized by me).
i need the costumized icon appears on the map!!
pd: i already change the path on the method DRAW()
here is my code.
myOpenMapView = (MapView)findViewById(R.id.openmapview);
myOpenMapView.setBuiltInZoomControls(true);
myMapController = myOpenMapView.getController();
myMapController.setZoom(12);
myOpenMapView.setMultiTouchControls(true);
ArrayList<OverlayItem> anotherOverlayItemArray;
anotherOverlayItemArray = new ArrayList<OverlayItem>();
GeoPoint geoPoint = new GeoPoint(Double.valueOf(lat),
(Double.valueOf(lng)));
anotherOverlayItemArray.add(new OverlayItem("US", "US", geoPoint));
myMapController.setCenter(geoPoint);
myMapController.animateTo(geoPoint);
DefaultResourceProxyImpl defaultResourceProxyImpl = new DefaultResourceProxyImpl(this);
MyItemizedIconOverlay myItemizedIconOverlay = new MyItemizedIconOverlay(anotherOverlayItemArray, null, defaultResourceProxyImpl);
myOpenMapView.getOverlays().add(myItemizedIconOverlay);
I had the same problem and I fixed it deleting the super.draw(...) call on draw overrided function of my own ItemizedIconOverlay class.
Hope it helps!
IMPORTANT EDIT: The solution explained above seems to cause problems on marker tap action (we have to call super.draw method).
To fix this I have left behind my CustomItemizedOverlay class and changed the icon using setMarker(Drawable d) method of OverlayItem on each element instead, rude but does the job.
Drawable newMarker = this.getResources().getDrawable(R.drawable.ic_launcher);
mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(anotherOverlayItemArray,
newMarker, "listener", new DefaultResourceProxyImpl(getActivity()));
mapView.getOverlays().add(mMyLocationOverlay);
or maybe the myLocationOverlay.enableMyLocation(); is enabled this means it will show the default marker for location on the map
Is it possible to crop the Google Map before integrating it into an application?
For example, my city will be the only area visible when I launch the application.
It is not possible to crop an area or any part of Maps, you can show your area initially when user view your app & disable navigating within the map by setClickable(false);
mapView.setBuiltInZoomControls(false);
List<overlay> mapOverlays = mapView.getOverlays();
GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
OverlayItem overlayitem = new OverlayItem(point, "This is my area");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
MapController mapController = mapView.getController();
mapController.animateTo(point);
mapController.setZoom(6);
where latitudeE6, longitudeE6 is your area's lat & Long
I am working on GoogleMap with MapView.Part of my project i am touching on the map and i am adding pin.My question is i want to remove pin which can added before. How can i do that i want to give Geopoint to the function.
Can anybody give me suggestion?
This is my code:`
public void AddPoint(Drawable drawable, MapView mapView, MotionEvent motionEvent) {
p = mapView.getProjection().fromPixels(
(int) motionEvent.getX(),
(int) motionEvent.getY()-50);
final MapController mc = mapView.getController();
mc.setZoom(16);
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
itemizedOverlay.addOverlay(new CustomOverlayItem(p,"","",""));
mapView.getOverlays().add(itemizedOverlay);
mc.animateTo(p);
mapView.invalidate();
}`
mapView.getOverlays().clear();
Call marker.remove(). To get the reference to the marker, you need to save the markers to a List when you create them, and then you can iterate over the List to find the ones you want.
I can take my location with myLocationOverlay easily, and I want to set as a center of my location, I tried map controller:
MapController mc = myMap.getController();
mc.animateTo();
mc.setCenter(myLocOverlay.getMyLocation());
these code didnt work so I changed
p = new GeoPoint((int) (myLocOverlay.getMyLocation().getLatitudeE6()), (int) (myLocOverlay.getMyLocation().getLongitudeE6()));
mc.setCenter(p);
But there is no good news. I took null pointer exception then I assigned new location before myLocationOverlay() but its not working.. Thanks for advance..
The animateTo can be used for this,
GeoPoint point = this.currentLocationOverlay.getMyLocation();
if(point==null)
return;
//center map on that geopoint
mc.animateTo(point);