Google Maps Android API - Styled Maps - android

From what I have read so far, it seems that there is no way to style Google Maps via the Android API.
Has anyone seen differently or know a way to style Google Maps on Android (change feature colors, etc.)?
From what I have seen, the only alternative to a full map library for Android (or iOS) is Mapbox, but their Android library is still under heavy development.

Google introduced Cloud-based Map Styling (however it is in Beta now). Using this feature, it is possible to set up a Map Id and a Map Style in Google Cloud Platform and to use it in the Android App (the only thing you need to do in the app is to specify the Map Id).
Here are the details:
https://developers.google.com/maps/documentation/android-sdk/cloud-based-map-styling
PS Here is the description of the 'old' option where you need to create a special json file and use it in the Android app to get a styled map:
https://developers.google.com/maps/documentation/android-sdk/styling

We can create styled maps as follows in android:
StyledMapDemoActivity.java
public class StyledMapDemoActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap = null;
private static final String TAG = StyledMapDemoActivity.class.getSimpleName();
private static final String SELECTED_STYLE = "selected_style";
// Stores the ID of the currently selected style, so that we can re-apply it when
// the activity restores state, for example when the device changes orientation.
private int mSelectedStyleId = R.string.style_label_default;
// These are simply the string resource IDs for each of the style names. We use them
// as identifiers when choosing which style to apply.
private int mStyleIds[] = {
R.string.style_label_retro,
R.string.style_label_night,
R.string.style_label_grayscale,
R.string.style_label_no_pois_no_transit,
R.string.style_label_default,
};
private static final LatLng SYDNEY = new LatLng(-33.8688, 151.2093);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mSelectedStyleId = savedInstanceState.getInt(SELECTED_STYLE);
}
setContentView(R.layout.styled_map_demo);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onSaveInstanceState(Bundle outState) {
// Store the selected map style, so we can assign it when the activity resumes.
outState.putInt(SELECTED_STYLE, mSelectedStyleId);
super.onSaveInstanceState(outState);
}
#Override
public void onMapReady(GoogleMap map) {
mMap = map;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 14));
setSelectedStyle();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.styled_map, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_style_choose) {
showStylesDialog();
}
return true;
}
/**
* Shows a dialog listing the styles to choose from, and applies the selected
* style when chosen.
*/
private void showStylesDialog() {
// mStyleIds stores each style's resource ID, and we extract the names here, rather
// than using an XML array resource which AlertDialog.Builder.setItems() can also
// accept. We do this since using an array resource would mean we would not have
// constant values we can switch/case on, when choosing which style to apply.
List<String> styleNames = new ArrayList<>();
for (int style : mStyleIds) {
styleNames.add(getString(style));
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.style_choose));
builder.setItems(styleNames.toArray(new CharSequence[styleNames.size()]),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
mSelectedStyleId = mStyleIds[which];
String msg = getString(R.string.style_set_to, getString(mSelectedStyleId));
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
Log.d(TAG, msg);
setSelectedStyle();
}
});
builder.show();
}
/**
* Creates a {#link MapStyleOptions} object via loadRawResourceStyle() (or via the
* constructor with a JSON String), then sets it on the {#link GoogleMap} instance,
* via the setMapStyle() method.
*/
private void setSelectedStyle() {
MapStyleOptions style;
switch (mSelectedStyleId) {
case R.string.style_label_retro:
// Sets the retro style via raw resource JSON.
style = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_retro);
break;
case R.string.style_label_night:
// Sets the night style via raw resource JSON.
style = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_night);
break;
case R.string.style_label_grayscale:
// Sets the grayscale style via raw resource JSON.
style = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_grayscale);
break;
case R.string.style_label_no_pois_no_transit:
// Sets the no POIs or transit style via JSON string.
style = new MapStyleOptions("[" +
" {" +
" \"featureType\":\"poi.business\"," +
" \"elementType\":\"all\"," +
" \"stylers\":[" +
" {" +
" \"visibility\":\"off\"" +
" }" +
" ]" +
" }," +
" {" +
" \"featureType\":\"transit\"," +
" \"elementType\":\"all\"," +
" \"stylers\":[" +
" {" +
" \"visibility\":\"off\"" +
" }" +
" ]" +
" }" +
"]");
break;
case R.string.style_label_default:
// Removes previously set style, by setting it to null.
style = null;
break;
default:
return;
}
mMap.setMapStyle(style);
}
}
StyledMapDemoActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />

Related

android multiple themes, one app

I need to develop an app, which can for some users (defined by server) set different app colors.
I have read a lot of custom theme with usage of attr.xml file, but android studio builder will be broken if I would use it.
So i have developed another approach - I subclassed Resorses class of my BaseActivity:
CustomResource customResource;
#Override
public Resources getResources() {
if (customResource == null) {
customResource = new CustomResource(super.getAssets(), super.getResources().getDisplayMetrics(), super
.getResources().getConfiguration());
}
return customResource;
}
public class CustomResource extends Resources {
public CustomResource(AssetManager assets, DisplayMetrics metrics, Configuration config) {
super(assets, metrics, config);
}
#Override
public int getColor(int id) throws NotFoundException {
Log.d("TAG", "id: " + id + " getResourceName: " + getResourceName(id));
Log.i("TAG", "Came Color: "+super.getColor(id));
return getColor ( getResourceName(id) , id);
}
public int getColor(String aString, int oldId) {
String packageName = getPackageName();
int resId = getIdentifier(getThemeColorName(aString),null,null);
Log.v("TAG", "resId: "+resId);
if (resId != 0) {
Log.i("TAG", "We SET Color: "+super.getColor(resId));
return super.getColor(resId);
} else {
return super.getColor(oldId);
}
}
private String getThemeColorName(String aString){
int pos = aString.lastIndexOf('/');
if (pos != -1){
aString = aString.substring(0, pos+1) + "b" + aString.substring(pos+1, aString.length());
}
Log.d("TAG", "aString NOW: " + aString);
return aString;
}
}
And retreive appropriet resource (just for testing, I am pulling out instead of "someColor" -> "bsomeColor".
As I look into log, everything is working, colors are being changing.
But if I set colors from xml (activities layout) I see all methods are being exected (sucessfully), but on my screen android epplyies colors without "b" prefix (BUT all my methods are being called - getColor() for every view, and I return super.getColor for an appropriate color, what I need!
Please, give me ideas how this can be solved, or give me other options to nicely introduce multiple themes, not breaking the xml editor

Integrating Dibs Payment Gateway in Android

I am working on Dibs Payment integration but unable to achieve success. All things are working good in demo mode but when merchant id is supplied to it then before opening card details form it gives an error "Data has been tampered. Checksome is not valid". I dont know what is it. After my googling i found it is something related to MAC calculated but how to calculate MAC in my code. My whole class for payment is as follows with all comments.
public class CheckOut extends Activity {
private static final String TAG = "DIBS." + CheckOut.class.getSimpleName();
private DibsPayment paymentWindow;
public static String total, resname, resid, userid, menunames, itemnames,
itemquantity, ordertype, address, city, contactno, pincode,
deliverttime, orderid;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkout);
RandomStringGenerator randomorderid = new RandomStringGenerator();
Intent i = getIntent();
// total=String.valueOf(1);
total = i.getStringExtra("grandTotal");
resname = i.getStringExtra("res_name");
resid = i.getStringExtra("res_id");
userid = i.getStringExtra("user_id");
menunames = i.getStringExtra("menu_names");
itemnames = i.getStringExtra("item_prices");
itemquantity = i.getStringExtra("item_quantity");
ordertype = i.getStringExtra("ordertype");
address = i.getStringExtra("address");
city = i.getStringExtra("city");
contactno = i.getStringExtra("phone");
pincode = i.getStringExtra("pin");
deliverttime = i.getStringExtra("delivery_time");
orderid = randomorderid.getAlphaNumeric(5);
Toast.makeText(
getApplicationContext(),
orderid + "\n" + resname + "\n" + resid + "\n" + userid + "\n"
+ ordertype + "\n" + address + "\n" + city + "\n"
+ pincode + "\n" + contactno + "\n" + deliverttime
+ "\n" + menunames + "\n" + itemnames + "\n"
+ itemquantity + "\n" + total, Toast.LENGTH_SHORT)
.show();
/*
* Intent intent=getIntent(); String []
* arrayList=intent.getStringArrayExtra("payment_item"); // int l_itr =
* arrayList.length; // while(l_itr.hasNext()) { for(int
* i=0;i<=arrayList.length-1;i++){
*
* #SuppressWarnings("rawtypes") //HashMap l_map = (HashMap)
* l_itr.next(); String item=arrayList[i]; Log.v(item, "item"); String
* item =(String)i.get(DatabaseHandler.KEY_ITEM); Log.v(item, "item");
* String unicost= (String)l_map.get(DatabaseHandler.KEY_UNITCOST);
* Log.v(unicost, "unicost"); String l_res_name = (String)
* l_map.get(DatabaseHandler.KEY_QUANTITY); Log.v(l_res_name,
* "quantity"); String l_street = (String)
* l_map.get(DatabaseHandler.KEY_TOTAL); Log.v(l_street, "total"); }
*/
paymentWindow = (DibsPayment) findViewById(R.id.DibsPayment);
// Set your listener implementation, to get callbacks in the life-cycle
// of a payment processing
paymentWindow
.setPaymentResultListener(new MyPaymentResultListener(this));
// Load the payment window with the payment data that suits the payment
// flow you need
// Please be patient, when loading on the emulator
paymentWindow.loadPaymentWindow(constructPaymentData());
}
/**
* Shows a "cancel" action in the options menu on the phone, which shows how
* to call cancel functionality into the payment window to cancel ongoing
* payment processing.
*/
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.payment_window_menu, menu);
return true;
}
/**
* If user chose "cancel" in options menu, we call "cancel" into payment
* window.
*/
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuitem_payment_window_cancel:
//
// Calling cancel into payment window cancels the ongoing payment
// processing.
// Because cancelling is an asynchronous process, you will need to
// wait for a callback
// to paymentCancelled on your PaymentResultListener listener,
// before being positive that
// payment window is done cancelling.
//
paymentWindow.cancelPayment();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/**
* #return the payment data instance that is needed as input to
* {#link DibsPayment#loadPaymentWindow(dk.dibs.android.library.PaymentData)}
*/
private PaymentData constructPaymentData() {
// IMPORTANT: This needs to be set to YOUR merchant number, that you
// have obtained through an
// agreement with DIBS.
// you can use the merchant "demo" for a demorun through the payment
// window // read information about demo mode in the documentation
String merchantId = "******";
//String merchantId = "demo";
// The currency the payment is to be processed in
String currencyCode = "DKK";
// You set this to your own orderId value
String yourOrderId = orderid;
// The amount to be paid, given in "least possible unit" (aka: "oerer")
long amount = (new Double(total)).longValue();
// The cards that is allowed to be used in payment window
List<String> payTypes = new ArrayList<String>();
payTypes.add("MC");
payTypes.add("MTRO");
payTypes.add("VISA");
// this will add fee to the payment window.
boolean calcfee = true;
// In this example, we simply use "PurchasePaymentData", which is a
// simple "buy-with-credit-card" flow,
// where no pre-authorization is performed.
//
// Look to other subclasses of PaymentData for the other supported
// flows.
//
PurchasePaymentData paymentData = new PurchasePaymentData(merchantId,
currencyCode, yourOrderId, amount, payTypes);
paymentData.setCalcfee(calcfee);
// Set this flag to "true", if you want to be able to use test cards.
// REMEMBER to reset this to false, in production !!!
paymentData.setTest(true);
// If you want checks (and payment failure) if the orderId you gave
// already have been payed.
paymentData.setUseUniqueOrderIdCheck(false);
// If you want MAC security calculations, you will need to pre-calculate
// a MAC value on your server,
// based on the values you give to this payment window, and set this
// pre-calculated MAC value like this.
//
paymentData.setCalculatedMAC("");
// Payment window supports loading cancel or callback URLs based on
// payment outcome.
// Another, and maybe better, way to do this in an app, is to listen for
// the proper callbacks
// on the listener you set on the payment window, and then do your own
// cancel or payment success
// handling against your own servers.
//
try {
paymentData.setCallbackUrl(new URL(
"http://****.demoprojects.in/accept.php"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
paymentData.setCancelUrl(new URL("http://****.demoprojects.in/accept.php"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
paymentData.setLanguage("en_UK");
paymentData.setTheme(Theme.ANDROID_DIBS);
// If you need to, you can pass custom options to the payment window,
// which will be posted back again.
//
// Map<String, String> yourCustomOptions = new HashMap<String,
// String>();
// yourCustomOptions.put("foo", "bar");
// paymentData.setCustomOptions(yourCustomOptions);
return paymentData;
}
/*
* public void delete() { DatabaseHandler readDatabase = new
* DatabaseHandler( getApplicationContext()); readDatabase.deleteAll(); }
*/
}
This is the first time i am working on payment. Please help me out as security is the main concern here.
Thanks in advance :)
Dibs allow MAC to be calculated by two algorithms The choice of algorithm is up to you. It currently handles MD5 and SHA-1. SHA-1 is recommended by Dibs as it provides better security.
SHA-1(data&currency&method&SecretKey&)
or
MD5(data&currency&method&SecretKey&)
data here is the string containing information regarding the amount and quantity of purchase.
Security > DebiTech DefenderTM > MAC Configuration, here you will find the secret key in dibs dashboard.
Click here for further reference:

android googleMaps v2 onMarkerclick comparison

I have a onMarkerClickListener on my google map which fires when a marker is pressed as it should.
the markers are created in a Tag class that creates the marker within itself on a map that is passed though:
instance of the list at the start of the map activity:
//tags
List<Tag> tags = new ArrayList<Tag>();
In the onCreate() of the activity that contains the googleMap I add the markers to a list:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....other code here
//add the markers to the map
tags.add(new Tag(map,1,"City Of Dundee", "Home Of The Jakey", DUNDEE, this.getResources(),R.drawable.ic_launcher));
tags.add(new Tag(map,2,"Some Place","This is some place",LOCATION_Z,this.getResources(),R.drawable.ic_launcher));
....other code here
}//end on create
Constructor for the Tag class:
public Tag(GoogleMap map, int atagID,String tagTitle, String tagSnippet, LatLng tagPosition, Resources resource, int id){
this.tagID = atagID;
this.position = tagPosition;
this.title = tagTitle;
this.snippet = tagSnippet;
this.icon = BitmapDescriptorFactory.fromResource(id);
this.theTag = map.addMarker(new MarkerOptions()
.position(tagPosition)
.title(tagTitle)
.snippet(tagSnippet)
.icon(icon));
}
This creates the tag and it display on the map properly
In the listener for the onMarkerClickedListener i compare the marker clicked on the map to the marker from the list but the if statement never passes, even when I compare the titles which are identical.
The Listener:
onMarkerClickListener = new OnMarkerClickListener(){
#Override
public boolean onMarkerClick(Marker marker) {
//for loop that goes over array or marker
//if marker is equal to mark in array
//do marker functionality
for(Tag currentTag : tags){
if(currentTag.theTag == marker){
switch(currentTag.tagID){
case 1:
//do something for that button
Toast.makeText(getApplicationContext(), "marker 1", Toast.LENGTH_SHORT).show();
return true;
case 2:
Toast.makeText(getApplicationContext(), "marker 2", Toast.LENGTH_SHORT).show();
return false;
default:
Toast.makeText(getApplicationContext(), "default", Toast.LENGTH_SHORT).show();
return false;
}
}else{
Toast.makeText(getApplicationContext(), "theTag " + currentTag.tagID + ": " + currentTag.theTag.getTitle(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "marker: " + marker.getTitle(), Toast.LENGTH_SHORT).show();
}
}
return false;
}
};
I hove no idea why it never reaches the switch statement any ideas?
I found the documentation i was looking for, don't know how i missed it.
As I have read you can't compare a marker using the '==' but you can using
if(markerA.equals(markerB)
{
}
Like so:
if(theTag.equals(marker){
//it will compare properly this way instead of returning false every time
}
Reference to website:
https://developers.google.com/maps/documentation/android/marker
You do not need the for loop in your code. When you do the equality test on the markers(using ==) it will return false, and never reach your switch. Instead try removing the for loop and just us.
switch(marker.getId()){
case 1:
//do something for that button
Toast.makeText(getApplicationContext(), "marker 1", Toast.LENGTH_SHORT).show();
return true;
case 2:
Toast.makeText(getApplicationContext(), "marker 2", Toast.LENGTH_SHORT).show();
return false;
default:
Toast.makeText(getApplicationContext(), "default", Toast.LENGTH_SHORT).show();
return false;
}
}else{
Toast.makeText(getApplicationContext(), "theTag " + currentTag.tagID + ": " + currentTag.theTag.getTitle(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "marker: " + marker.getTitle(), Toast.LENGTH_SHORT).show();
}
Expanding on #MaciejGórski comment from the selected answer I would suggest using the ID of the marker (which is oddly a string).
This helps you avoid keeping hard references to Markers which themselves have references to the GoogleMap object, and thus the entire MapView/MapFragment/SupportMapFragment
In my class I have:
private Map< String, MyObject > markersMap = new HashMap< String, MyObject >();
Then when I create the markers I add them to the map:
markersMap.put( marker.getId(), myObj );
Then in the listener I am able to retrieve myObj like this
#Override
public void onInfoWindowClick( Marker m )
{
Log.v( TAG, "onInfoWindowClick m.getId = " + m.getId() );
MyObject myObj = markersMap.get( m.getId() );
Log.v( TAG, "onInfoWindowClick myObj = " + myObj );
}
This way I avoid leaking the Views/Activity/Map etc
The == operator will compare the direction of memory of both objects (which are not the same, since are different instances) instead of the object properties.
the equals method, will compare the value of the attributes of your object or if you override the equals you can compare what ever you want, which will be more suitable to you.

how to send longitude and latitude to map application to show particular co-ordinates on map?

I have an application in which on clicking a button, or on changing place, or after a particular time, I am able to get longitude and latitude values. I want to use this values to show them on Google Map application. I am opening a map using intent to show location, but somehow its not showing cordinates which I am getting.
This is a working piece of code that I use in one of my apps. This code also includes a check to find out if the user has Google Maps installed on his / her device. If the check returns the app as installed, then the function will pass on the data to the app. If the check fails, it displays an AlertDialog informing the use that the app is not installed.
protected void showMap() {
boolean installedMaps = false;
// CHECK IF GOOGLE MAPS IS INSTALLED
PackageManager pkManager = getPackageManager();
try {
#SuppressWarnings("unused")
PackageInfo pkInfo = pkManager.getPackageInfo("com.google.android.apps.maps", 0);
installedMaps = true;
} catch (Exception e) {
e.printStackTrace();
installedMaps = false;
}
// SHOW THE MAP USING CO-ORDINATES FROM THE CHECKIN
if (installedMaps == true) {
String geoCode = "geo:0,0?q=" + PLACE_LATITUDE + ","
+ PLACE_LONGITUDE + "(" + PLACE_NAME + ")";
Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW,
Uri.parse(geoCode));
startActivity(sendLocationToMap);
} else if (installedMaps == false) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
CheckinsDetails.this);
// SET THE ICON
alertDialogBuilder.setIcon(R.drawable.ic_launcher);
// SET THE TITLE
alertDialogBuilder.setTitle("Google Maps Not Found");
// SET THE MESSAGE
alertDialogBuilder
.setMessage(R.string.noMapsInstalled)
.setCancelable(false)
.setNeutralButton("Got It",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.dismiss();
}
});
// CREATE THE ALERT DIALOG
AlertDialog alertDialog = alertDialogBuilder.create();
// SHOW THE ALERT DIALOG
alertDialog.show();
}
}
This line of code mentioned below sends it to Google Maps and instead of displaying just the Pin also displays the location name.
String geoCode = "geo:0,0?q=" + PLACE_LATITUDE + ","
+ PLACE_LONGITUDE + "(" + PLACE_NAME + ")";
EDIT: If you do not wish to display the PLACE_NAME, modify that particular line with: geo:latitude,longitude instead of the one used in the code block.
Check this link for further combinations possible, like zoom for example: http://developer.android.com/guide/appendix/g-app-intents.html
Double latitud = 37.40*1E6;
Double longitud = -5.99*1E6;
GeoPoint loc =
new GeoPoint(latitud.intValue(), longitud.intValue());
controlMapa.animateTo(loc);
int zoomActual = mapa.getZoomLevel();
for(int i=zoomActual; i<10; i++)
controlMapa.zoomIn();
}
where
controlMapa = mapa.getController();
mapa = (MapView)findViewById(R.id.linearLayout1);
For more info: MapView Tutorial
try this:
String url = "http://maps.google.com/maps?daddr="+ ze.getCoordenada().getLatitude() + ","+ ze.getCoordenada().getLongitude();
Intent goZe = new Intent(Intent.ACTION_VIEW);
goZe.setData(Uri.parse(url));
startActivity(goZe);
you will get a prompt to use browser or Maps
somehow, using this string on google
String url = "http://maps.google.com/maps?daddr="+ ze.getCoordenada().getLatitude() + ","+ ze.getCoordenada().getLongitude();
while selecting google maps shows oposite longitude and latitude while the website is correct.
maybe i am using an old version of google maps
public void showMap(long latitude, long longitude) {
String geoCode = "geo:0,0?q=" + latitude + ","
+ longitude;
Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW, Uri.parse(geoCode));
if (sendLocationToMap.resolveActivity(getPackageManager())!=null){
startActivity(sendLocationToMap);
}
else {
Toast.makeText(this,"No Application To handle the Request",Toast.LENGTH_SHORT).show();
}
}

Cannot access resource icons when running with osmdroid-android-3.0.7

I am trying to start a simple map activity that displays a map an a couple of markers using osmdroid-android-3.0.7 library. The code worked under an older version (1.10). I am getting the following error:
02-03 15:14:30.574: E/AndroidRuntime(10277): Caused by: java.lang.IllegalArgumentException: Resource not found: marker_default.png
When I unzipped the jar file I can see a list of icons in the top level directory and one of them is indeed marker_default.png. This is the snippet of the code:
public class MapDisplay extends Activity
{
private MapView mapView;
private ResourceProxy resProxy;
private ItemizedOverlay<OverlayItem> locationOverlay;
public void onCreate(final Bundle savedState)
{
super.onCreate(savedState);
resProxy = new DefaultResourceProxyImpl(getApplicationContext());
final RelativeLayout rl = new RelativeLayout(this);
mapView = new MapView(this, 256);
mapView.setBuiltInZoomControls(true);
mapView.getController().setZoom(6);
mapView.getController().setCenter(new GeoPoint(51500000, 5400000));
rl.addView(mapView, new RelativeLayout.LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
OverlayItem o1 = new OverlayItem("Location 1", "Comment",
new GeoPoint(51500000, 5400000));
o1.setMarker(getResources().getDrawable(R.drawable.icall));
items.add(o1);
OverlayItem o2 = new OverlayItem("Location 2", "Comment",
new GeoPoint(52500000, 5500000));
o2.setMarker(getResources().getDrawable(R.drawable.icall));
items.add(o2);
this.locationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>()
{
#Override
public boolean onItemSingleTapUp(final int index,
final OverlayItem item)
{
Toast.makeText(
MapDisplay.this,
"Item '" + item.mTitle + "' (index=" + index
+ ") got single tapped up", Toast.LENGTH_LONG).show();
return true; // We 'handled' this event.
}
#Override
public boolean onItemLongPress(final int index,
final OverlayItem item)
{
Toast.makeText(
MapDisplay.this,
"Item '" + item.mTitle + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
}
}, resProxy);
this.mapView.getOverlays().add(this.locationOverlay);
mapView.invalidate();
this.setContentView(rl);
}
}
When I tried to use a simple overlay and therefore did not set any icons for the marker then I got the same error except it referred to person.png (that icon is also in the unzipped jar file).
I have added the jar file via project properties and can access the api just fine.
Why can't I access the icons?
BTW, I tried to copy the icons into my project but I got the same error.
Thanks, Ania
I had the same problem - in the latest jar (3.0.8) the issue is fixed.
There is an issue in the bug tracker which I think has a solution for this. Have not had the issue myself I provide my own bitmap. I do remember all the proxy stuff being confusing and troublesome.

Categories

Resources