Set multiple marker in osmdroid - android

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.

Related

No map displayed when using bounding box; setScrollableAreaLimitDouble

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);

Cropping Google 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

How can I add strings to my custom map marker in Android?

I have created a map marker that is positioned on my map by finding the users location, but I am trying to add strings to the map marker and cannot get it to work. Here is my onCreate method where the location is set. The last part of the method shows placing pinpoint at location, I thought that the overlay item would take string parameters as follows:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
// Displaying Zooming controls
mapView= (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
//Manually place a pin by touching the map
touchy t = new touchy();
overlayList = mapView.getOverlays();
overlayList.add(t);
compass = new MyLocationOverlay(Maps.this, mapView);
overlayList.add(compass);
controller = mapView.getController();
d = getResources().getDrawable(R.drawable.androidmarker);
//placing pinpoint at location
lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria crit = new Criteria();
towers = lm.getBestProvider(crit, false);
Location location = lm.getLastKnownLocation(towers);
if(location != null){
lat = (int) (location.getLatitude()* 1E6);
longi = (int) (location.getLongitude()* 1E6);
GeoPoint ourLocation = new GeoPoint(lat, longi);
controller.animateTo(ourLocation);
controller.setZoom(6);
OverlayItem overlayitem = new OverlayItem(ourLocation, "First string", "Second string");
HelloItemizedOverlay custom = new HelloItemizedOverlay(d, Maps.this);
custom.insertPinpoint(overlayitem);
overlayList.add(custom);
}
else{
Toast.makeText(Maps.this, "Couldn't get provider", Toast.LENGTH_SHORT).show();
}
}
Can anyone see what I am doing wrong? Is this the wrong way to do this? Eventually I want to pass a name and high-score to the location which will be retrieved from another class as two strings.
I appreciate any advice at all.
Follow the following tutorial:
http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/
In this he is creating an ItemizedOverly
HelloItemizedOverlay extends ItemizedOverlay<OverlayItem>
This will help you in adding a map overlay with text

How can I show my location on google maps in android

I have a google maps app that takes an array of points and puts them on a map. I want to add the little blue dot that moves as the user moves around. I haven't found any tutorials on how to do this. Here is an example of what I need
Note that the blue dot also has a blue ring that pulsates and it follows you when you start walking.
Thanks
EDIT I have found the function drawMyLocation, however I do not know where to place it. Here is my map activity and my itemized overlay (I am using a balloon itemized overlay to create the popup dialog effect)
MapView mapView = (MapView) findViewById(R.id.mapView);
List<Overlay> mapOverlays = mapView.getOverlays();
for (int i = 0; i < mList.size(); i++) {
Drawable drawable = null;
for (int k = 0; k < ImTracking.pList.size(); k++) {
if (mList.get(i).getId()
.equals(ImTracking.pList.get(k).getid())) {
mList.get(i).setName(
ImTracking.pList.get(k).getName());
if (mList.get(i).getMostRecent()) {
drawable = Maps.this.getResources()
.getDrawable(
pincolorstar[ImTracking.pList
.get(k).getPosition()]);
} else {
drawable = Maps.this
.getResources()
.getDrawable(
ImTracking.pincolors[ImTracking.pList
.get(k).getPosition()]);
}
}
}
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
drawable, mapView);
GeoPoint myPoint = new GeoPoint((int) (mList.get(i)
.getLatitude() * 1E6), (int) (mList.get(i)
.getLongitude() * 1E6));
OverlayItem overlayitem = new OverlayItem(myPoint, mList
.get(i).getName(), mList.get(i).getTime());
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
The above part adds all the pins to the map, the next part is where I attempt to add the mylocation overlay
MyLocationOverlay myLocationOverlay=new MyLocationOverlay(Maps.this, mapView);
myLocationOverlay.enableMyLocation();
mapOverlays.add(myLocationOverlay);
MapController mc = mapView.getController();
mc.zoomToSpan(Math.abs(maxLat - minLat),
Math.abs(maxLon - minLon));
mc.animateTo(new GeoPoint((maxLat + minLat) / 2,
(maxLon + minLon) / 2));
} catch (Exception e) {
e.printStackTrace();
}
Just adding myLocationOverlay to mapOverlays does not display the blue dot.
You might want to see MyLocationOverlay and see if that can fit into your requirement
Sample illustration below:
List overlaysoverlays = mapView.getOverlays();
// "this" refers to your activity
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation();
overlays.add(myLocationOverlay);

How to to make 2 MapView on one Activity?

Is it possible to make 2 MapView on one Activity ?
If so, How to make it ?
I've tried but no luck.
Thanks in advance.
The short answer is no.
Currently Android supports only one MapView per MapActivity.
yes possible, I used this code for two different kinds of maps------ 1. for getting gps location------2. for getting some location when it is searched by its area/city/country name. The code is,
public void mapDisplay(double lat, double lng, int arg){
if(arg == 1){
mapView = (MapView)findViewById(R.id.map_view);
}
else if (arg ==2 ){
mapView = (MapView)findViewById(R.id.map_view2);
}
mapView.setBuiltInZoomControls(true);
//mapView.setStreetView(true);
//mapView.setTraffic(true);
//mapView.setSatellite(true);
// to display the pin point
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
GeoPoint point = new GeoPoint((int) (lat * 1E6), (int)(lng * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapView.getController().setZoom(18);
mapView.getController().setCenter(point);
mapView.getController().animateTo(point);
mapView.invalidate();
}
Note: Make sure that you have set the ContentViews before calling this method and
int arg
is used here to indicate that which mapView is going to be called.....I used

Categories

Resources