how to use custom pointers in osmdroid? - android

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.

Related

How to set margins for IconGenerator in Google Map utils?

I been using google map utils for a couple of days now and it seemed so fine.
This is code im using to add a marker with a custom layout file to the map.
IconGenerator mIconGenerator = new IconGenerator(getApplicationContext());
View mView = getLayoutInflater().inflate(R.layout.map_location_label, null);
TextView mInfoWindowText = (TextView) mView.findViewById(R.id.location);
mInfoWindowText.setText(Takzy.pickupLocationText);
mIconGenerator.setContentView(mView);
mIconGenerator.setRotation(-90);
mIconGenerator.setContentRotation(90);
mIconGenerator.setContentPadding(0, 0, 0, 0);
view.Bitmap mBitmapPickupLocation = mIconGenerator.makeIcon();
Bitmap mBitmapDestinationLocation = mIconGenerator.makeIcon(Takzy.destinationLocationText + " >");
// add the pickup marker to map
mMap.addMarker(
new MarkerOptions().title(Takzy.pickupLocationText)
.position(Takzy.pickupLatLng)
.icon(BitmapDescriptorFactory
.fromBitmap(mBitmapPickupLocation))
.anchor(mIconGenerator.getAnchorU(), mIconGenerator.getAnchorV()));
Everything is okay but as you can see, my text gets cut from the marker label. I have tried googling, read the docs over and over, and none of them worked.
it will work fine if I do not rotate the marker. but I need my marker rotated.
Can someone point out what might be the issue is?

Animate Marker Change Position in Xamarin.Android Google Maps

I am trying to animate change marker position in Xamarin android Google Map
var markerWithIcon = new MarkerOptions();
markerWithIcon.SetPosition(new LatLng(e.Latitude, e.Longitude));
var marker = googleMap.AddMarker(markerWithIcon);
Setting its position
marker.Position = new LatLng(e.Latitude, e.Longitude);
How to change position with linear animation? Thanks in advance.

OSMdroid add custom icons to ItemizedOverlay

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

How to plot a pre-build map from google maps on a MapView

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

OnTouchEvent in a MapItemizedOverlay

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.

Categories

Resources