Reputation: 952
I have a Activity that displays a map for a Android app using Google Maps and I want to replace the Yellow Marker I am currently using with a ping image that I created called fillingstation.png. How would I go about doing that as I am fairly new to Android App Development.
MapViewActivity.java
private void showFuelStops(String location) throws IOException{
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses;
addresses = geocoder.getFromLocationName(location, 1);
if(addresses.size() > 0) {
BitmapDescriptor subwayBitmapDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW);
double latitude= addresses.get(0).getLatitude();
double longitude= addresses.get(0).getLongitude();
LatLng subLoc = new LatLng(latitude, longitude);
Marker fuelMarker = map.addMarker(new MarkerOptions().position(subLoc).icon(subwayBitmapDescriptor).title("Subway, " + location));
}
}
Upvotes: 0
Views: 10290
Reputation: 1006664
If the PNG file is a resource (i.e., it is in res/drawable-NNNN/
for various densities), use fromResource()
instead of defaultMarker()
on BitmapDescriptorFactory
.
If the PNG file is an asset (i.e., it is in assets/
in your project), use fromAsset()
.
If the PNG file is a file on the device's internal storage, use fromFile()
.
Upvotes: 7