I am using ItemizedIconOverlay class and I'm currently displaying events on the map along with the user's position with the same default icon.
How do I change the icon set for each overlay?
Is there something similar to the google.maps example:
drawable = getResources().getDrawable(R.drawable.marker);
drawable3 = getResources().getDrawable(R.drawable.disruption);
drawable2 = getResources().getDrawable(R.drawable.marker_me);
itemizedOverlay = new MyItemizedOverlay(drawable, mapView);
itemizedOverlay2 = new MyItemizedOverlay(drawable2, mapView);
itemizedOverlay3 = new MyItemizedOverlay(drawable3, mapView);
I had each itemizedOverlay have its own marker...
How do I do this with Open Street Maps?
mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems, new Glistener(), mResourceProxy);
Thank you for your help and its a shame not much support is available online for this open source project ...
Presumably your mItems is an ArrayList of OverlayItems created like:
mItems = new ArrayList<OverlayItem>();
To this list you will be adding individual OveralyItems, so when you create each item you can do it like this, setting the marker before you add it to the list:
OverlayItem olItem = new OverlayItem("Here", "SampleDescription", point);
Drawable newMarker = this.getResources().getDrawable(R.drawable.mymarker);
olItem.setMarker(newMarker);
mItems.add(olItem);
where mymarker is a .png in your drawables folder.
Update - to set default marker for whole overlay, change
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems, new Glistener(), mResourceProxy);
to
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems, newMarker, new Glistener(), mResourceProxy);
where newMarker is as before
Related
I am using OSMDroid and this code gives default markers to point my location. How do i put custom markers in place of the default markers? How do i import a new drawable?
anotherOverlayItemArray = new ArrayList<OverlayItem>();
anotherOverlayItemArray.add(new OverlayItem("KTM2", "KTM2", myLocation));
ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = new
ItemizedIconOverlay<OverlayItem>( this, anotherOverlayItemArray,myOnItemGestureListener);
mapView.getOverlays().clear();
mapView.getOverlays().add(anotherItemizedIconOverlay);
mapView.invalidate();
You can set a specific marker to each OverlayItem:
OverlayItem item = new OverlayItem("KTM2", "KTM2", myLocation);
Drawable myMarker = getResources().getDrawable(markerResId);
item.setMarker(myMarker);
anotherOverlayItemArray.add(item);
You can also get rid of the ItemizedIconOverlay/OverlayItem approach by using the OSMBonusPack Marker.
Please guide me how to do animated marker/ pin/ overlay icon on map.
I tried lot from last 2 day but i am not getting success.
Thanks in advance..
Not working
res/drawable/map_marker.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/ecall_lowon" android:duration="200" />
<item android:drawable="#drawable/ecall_mediumoff" android:duration="200" />
Java code
Drawable drawable = this.getResources().getDrawable(R.drawable.map_marker);
MapItemizedOverlay mapItemizedOverlay = new MapItemizedOverlay(drawable, this);
GeoPoint geoPoint1 = new GeoPoint((int)(9.982878 * 1E6), (int)(76.285774 * 1E6));
GeoPoint geoPoint2 = new GeoPoint((int)(9.973928 * 1E6), (int)(76.276824 * 1E6));
OverlayItem overlayItem1 = new OverlayItem(geoPoint1, "Title1", "");
OverlayItem overlayItem2 = new OverlayItem(geoPoint2, "Title2", "");
mapItemizedOverlay.addOverlayItems(overlayItem1);
mapItemizedOverlay.addOverlayItems(overlayItem2);
mapView.getOverlays().add(mapItemizedOverlay);
But not getting success...
An animation defined in XML that shows a sequence of images in order (<animation-list />) may not work to show blink pin on map
I have work around this and find one of the solutions
Idea: Two drawables.., Runnable and handler, SetPin_On() and SetPin_Off(), In SetPin_On method use one image and in SetPin_Off method use another image,on each function calling clear overlay and add again
Resources: Take two images say pin_on, pin_off
Coding: Runnable with handler is required to set the pins in intervals
Example:
Handler handler=new Handler();
int check=0;
Runnable r=new Runnable()
{
#Override
public void run()
{
if(check==0)
{
SetPin_On();
check=1;
}
else if(check==1)
{
SetPin_Off();
check=0;
}
handler.postDelayed(this, 500);
}
};
And in SetPin_On method set the pin_on image on overlay and in SetPin_Off method again set pin_off image by clearing previous overlay
SetPin_On:
void SetPin_On()
{
mapOverlays = mapView.getOverlays();
mapOverlays.clear();
res =getResources();
drawable = res.getDrawable(R.drawable.pin_on);
itemizedOverlay = new CustomItemizedOverlay(drawable,this, mapView);
point = new GeoPoint((int)(Double.parseDouble(lati)*1E6),(int)(Double.parseDouble(longi)*1E6));
overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapController = mapView.getController();
mapController.animateTo(point);
mapController.setZoom(6);
}
SetPin_Off:
void SetPin_Off()
{
mapOverlays = mapView.getOverlays();
mapOverlays.clear();
res =getResources();
drawable = res.getDrawable(R.drawable.pin_off);
itemizedOverlay = new CustomItemizedOverlay(drawable,this, mapView);
point = new GeoPoint((int)(Double.parseDouble(lati)*1E6),(int)(Double.parseDouble(longi)*1E6));
overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapController = mapView.getController();
mapController.animateTo(point);
mapController.setZoom(6);
}
This is one solution to get blinking pin.May not efficient but result is very accurate
See here for another solution
i wanna display user location on mapview and i could it. but i cant update geopoint when user move to another location at this time - when look the map- how can i do that?
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(resID);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
GeoPoint point = new GeoPoint((int)latd,(int)lond);
OverlayItem overlayitem = new OverlayItem(point, name, name);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
in your onLocationChanged() of your Location Listener you need to write the same code again,
List<Overlay> mapOverlays = mapView.getOverlays();
mapOverlays.clear() // add this to remove previous
Drawable drawable = this.getResources().getDrawable(resID);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
GeoPoint point = new GeoPoint((int)latd,(int)lond);
OverlayItem overlayitem = new OverlayItem(point, name, name);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
I'm trying to read a map from a link (http://maps.google.com/maps/ms?msid=216892338463540803496.000494dd57eb5ebce6db2&msa=0) and plot it on a MapView, is it possible?
As you posted more information in my previous answer ("but I don't want to parse the KML and plot point by point. I was wondering if theres a way to plot all at once"), I can now redifine my answer.
You should try these lines and adapt it to your needs:
Intent mapIntent = new Intent(Intent.ACTION_VIEW);
Uri uri1 = Uri.parse("geo:0,0?q=http://code.google.com/apis/kml/
documentation/KML_Samples.kml");
mapIntent.setData(uri1);
startActivity(Intent.createChooser(mapIntent, "Sample"));
Unfortunately, you won't have any control, as this is not a MapActivity.
If you plan to add more stuff on your map, you have to try my first proposal and parse yourself the kml!
Similar question: How to use kml file on mapView in Android
You can draw on the Map with Overlays
Look at this tutorial: http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
GeoPoint point = new GeoPoint(30443769,-91158458);
OverlayItem overlayitem = new OverlayItem(point, "Laissez les bon temps rouler!", "I'm in Louisiana!");
GeoPoint point2 = new GeoPoint(17385812,78480667);
OverlayItem overlayitem2 = new OverlayItem(point2, "Namashkaar!", "I'm in Hyderabad, India!");
itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.addOverlay(overlayitem2);
mapOverlays.add(itemizedoverlay);
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
}
I have a MapView with a MapItemizedOverlay, like this :
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
itemizedOverlay = new MapItemizedOverlay(drawable);
OverlayItem overlayitem = new OverlayItem(p, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
I want to know when the user touches the AndroiMarker, so I can show some info about that specific place. How do I do that ?
Tks in advance!
Implement onTap() in your MapItemizedOverlay class.
Here is an example.