I am trying to load marker icons from URL but it's not showing me the icons on a map.What thing I am doing wrong.When I am using Bitmap to load icons it's working.
Picasso image load is not working for me.
I got the item name in a log:
>
....
D/success: #+ Set bitmap for Duke Of Wellington PT size: #3
D/success: #+ Set bitmap for Dante Gabriel Rossetti PT size: #2
D/success: #+ Set bitmap for Pierre Teilhard de Chardin PT size: #1
Here is my complete code :
private class CreateProductListTask extends AsyncTask<Void, Void, List<Product>> {
private String serverUrl;
public CreateProductListTask(String url) {
super();
this.serverUrl = url;
}
#Override
protected List<Product> doInBackground(Void... params) {
.....
JSONObject response = new JSONObject(stringBuffer.toString());
List<Product> products = new ArrayList<>();
HashMap<String, Bitmap> iconsMap = new HashMap<>();
try {
JSONArray productsJSON = response.getJSONArray("all_products");
for (int ixProduct = 0; ixProduct < productsJSON.length(); ixProduct++) {
JSONObject productJSON = productsJSON.getJSONObject(ixProduct);
String mapIconStr = productJSON.getString("map_icon");
URI uri = new URI(mapIconStr);
String[] segments = uri.getPath().split("/");
String iconName = segments[segments.length - 1];
// percetn-encode URL
String mapIconPath = mapIconStr.substring(0, mapIconStr.indexOf(iconName));
String iconUrlString = mapIconPath + URLEncoder.encode(iconName, "UTF-8");
// replace "http:" with "https:"
iconUrlString = iconUrlString.replace("http:", "https:");
try {
Product product = new Product();
product.id = productJSON.getString("ID");
product.name = productJSON.getString("post_title");
product.lat = productJSON.getDouble("latitude");
product.lon = productJSON.getDouble("longitude");
id = product.id;
System.out.println("my Id stored" + id);
product.icons= iconUrlString;
products.add(product);
} catch (Exception ignore) {
}
}
} catch (JSONException ex) {
Log.e("App", "Failure", ex);
}
return products;
} catch (Exception ex) {
Log.e("App", "yourDataTask", ex);
return null;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
#Override
protected void onPostExecute(List<Product> products) {
if (products != null) {
PoiTarget pt;
for (final Product product : products) {
Marker marker = googlemap.addMarker(new MarkerOptions()
.position(new LatLng(product.lat, product.lon))
.title(product.name)
/* .icon(BitmapDescriptorFactory.fromBitmap(product.icon))*/);
pt = new PoiTarget(marker);
poiTargets.add(pt);
Picasso.with(Frnt_mapActivity.this)
.load(product.icons)
.into(pt);
markerIds.put(marker, product.id);
}
}
}
}
//--------------------------------------------------------
// Inner class
//--------------------------------------------------------
class PoiTarget implements Target {
private Marker m;
public PoiTarget(Marker m) { this.m = m; }
#Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
m.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
poiTargets.remove(this);
Log.d("success"," #+ Set bitmap for "+m.getTitle()+" PT size: #"+poiTargets.size());
}
#Override public void onBitmapFailed(Drawable errorDrawable) {
Log.e("Load Image Failed"," #+ [ERROR] Don't set bitmap for "+m.getTitle());
poiTargets.remove(this);
}
#Override public void onPrepareLoad(Drawable placeHolderDrawable) {
}
}
Use Glide for this purpose , it loads bitmap faster than picasso. Sometimes picasso throws error while loading but in Glide this thing does not happens.
also Dont forget to close and reopen the marker after loading the image. See code below.
if (marker.isInfoWindowShown()) {
marker.hideInfoWindow();
marker.showInfoWindow();
}
let me know if you still have confusion . i will post my full code.
Replace this code
#Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
m.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
poiTargets.remove(this);
Log.d("success"," #+ Set bitmap for "+m.getTitle()+" PT size: #"+poiTargets.size());
}
with
#Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
poiTargets.remove(this);
m.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
Log.d("success"," #+ Set bitmap for "+m.getTitle()+" PT size: #"+poiTargets.size());
}
Map<String, List<Driver>> markerMap = new HashMap<String, List<Driver>>();
private List<Driver> markerArray = new ArrayList<Driver>();
public void markerDriver() {
markerArray = new ArrayList<>();
Firebase ref = new Firebase(Config.FIREBASE_URL_DRIVER);
ref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getChildrenCount() == 0) {
markerInfo();
} else {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Toast.makeText(MainMapActivity.this, "for", Toast.LENGTH_SHORT).show();
name = snapshot.child("driversName").getValue().toString().trim();
busNum = snapshot.child("busNum").getValue().toString().trim();
latitude = Double.valueOf(snapshot.child("latitude").getValue().toString().trim());
longitude = Double.valueOf(snapshot.child("longitude").getValue().toString().trim());
availableSeat = snapshot.child("availableSeat").getValue().toString().trim();
estimatedTime = snapshot.child("estimatedTime").getValue().toString().trim();
if ((!latitude.equals(null) || latitude.equals(0)) && (!longitude.equals(null) || longitude.equals(0)) && availableSeat.equals("") && (!estimatedTime.equals("") || estimatedTime.equals("0"))) {
convertLatLong();
getTotalPass();
markerArray.add(new Driver(name, totalPassenger, busNum, latitude, longitude, currentLocation, estimatedTime));
markerMap.put("key"+key++, markerArray);
}
}
for (i = 0; i < markerArray.size(); i++) {
createMarker(markerArray.get(i).getDriversName(), markerArray.get(i).getTotalPassenger(), markerArray.get(i).getBusNum(), markerArray.get(i).getLatitude(), markerArray.get(i).getLongitude(), markerArray .get(i).getLocation(), markerArray.get(i).getEstimatedTime());
}
}
}
#Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(MainMapActivity.this, "markerDriver: " + firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
I am putting my arrayList inside the HashMap because ArrayList alone don't have the capability to edit/update some data inside the list. So what I am trying to do is how do I retrieve the data inside the HashMap and createMarker
protected void createMarker(String driversName, final int totalPass, final String busNum, double latitude, double longitude, String location, String estimatedTime) {
Marker marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(location)
.snippet("Driver's Name: " + driversName + "\nTotal Passenger: " + totalPass + "\nBus number: " + busNum+"\nEstimated time: "+estimatedTime));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(com.google.android.gms.maps.model.Marker marker) {
dialogInfo(marker);
return true;
}
});
}
1.First create a POJO class like this
public class InterRejectedHistory {
String seeker_role,rejected_date;
String SeekerType;
public InterRejectedHistory(String seeker_role,String seekerType) {
this.seeker_role = seeker_role;
this.SeekerType= seekerType;
}
public String getSeekerType() {
return SeekerType;
}
public void setSeekerType(String seekerType) {
SeekerType = seekerType;
}
public InterRejectedHistory() {
}
public String getSeeker_role() {
return seeker_role;
}
public void setSeeker_role(String seeker_role) {
this.seeker_role = seeker_role;
}
public String getRejected_date() {
return rejected_date;
}
public void setRejected_date(String rejected_date) {
this.rejected_date = rejected_date;
}}
2.Step 2 [set the values from your class]
InterRejectedHistory interRejectedHistory;
List<InterRejectedHistory> dbList;
dbList=new ArrayList<InterRejectedHistory>();
interRejectedHistory.setSeeker_role(c.getString("SEEKERROLE"));
interRejectedHistory.setSeekerType(c.getString("SEEKERTYPE"));
dbList.add(new InterRejectedHistory(interRejectedHistory.getSeeker_role(),interRejectedHistory.getSeekerType()));
Note : In Mycase i was set the values in POJO and loaded into a adapter.
Wherever you want get the value from POJO class
ArrayList<InterRejectedHistory> list;
role.setText(list.get(position).getSeeker_role());
Happy Coding!
The marker has an icon property and it contains a bitmap of the user's Facebook profile picture.
I'm not really sure why the first marker doesn't load. But if you post a second, third or 4th (etc...) it works completely fine!
I don't have any other markers being added in my code other than the block of code below.
EDIT: This is important. The 'bitmap' value seems to be null on the first try. So it seems the if statement with the condition 'bitmap!=null' is catching it and preventing it from posting the first marker...
static Bitmap bitmap = null;
private Target loadtarget;
globalMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng point) {
vibe.vibrate(100);
AccessToken accessToken = AccessToken.getCurrentAccessToken();
MarkerOptions marker = new MarkerOptions().position(
new LatLng(point.latitude, point.longitude))
.title("New Marker");
Log.e("TAG", accessToken.getUserId());
String imageURL = new String("https://graph.facebook.com/" + accessToken.getUserId() + "/picture?type=small");
loadBitmap(imageURL);
if(bitmap!=null) {
globalMap.addMarker(marker
.position(point)
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.anchor(0.5f, 1));
}
}
});
}
public void loadBitmap(String url) {
if (loadtarget == null) loadtarget = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// do something with the Bitmap
handleLoadedBitmap(bitmap);
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getActivity()).load(url).into(loadtarget);
}
public void handleLoadedBitmap(Bitmap b) {
bitmap = b;
}
You are right, bitmap will be null on the first long click because there's no time to load bitmap. You are calling load() and immediately after that trying to show bitmap.
You can load bitmap not in the long click listener but before, may be in the same place of code where you're setting that listener.
String imageURL = new String("https://graph.facebook.com/" + accessToken.getUserId() + "/picture?type=small");
loadBitmap(imageURL);
globalMap.setOnMapLongClickListener(
// ...
// the same code without imageURL initialization and bitmap loading
);
Follow the Documentation
static Bitmap bitmap = null;
private Target loadtarget;
globalMap.setOnMapLoadedCallback(new OnMapLoadedCallback() {
#Override
public void onMapLoaded() {
globalMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng point) {
vibe.vibrate(100);
AccessToken accessToken = AccessToken.getCurrentAccessToken();
MarkerOptions marker = new MarkerOptions().position(
new LatLng(point.latitude, point.longitude))
.title("New Marker");
Log.e("TAG", accessToken.getUserId());
String imageURL = new String("https://graph.facebook.com/" + accessToken.getUserId() + "/picture?type=small");
loadBitmap(imageURL);
if(bitmap!=null) {
globalMap.addMarker(marker
.position(point)
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.anchor(0.5f, 1));
}
}
});
}
});
public void loadBitmap(String url) {
if (loadtarget == null) loadtarget = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// do something with the Bitmap
handleLoadedBitmap(bitmap);
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getActivity()).load(url).into(loadtarget);
}
public void handleLoadedBitmap(Bitmap b) {
bitmap = b;
}
I found out why it wasn't posting on the first try. It's because I was calling my method loadBitmap(..) too late, I felt like the process of it retrieving the image and loading it into the target value was too long for the clickListener which instantly places the marker. I just assumed that so I called it earlier, in my method onMapReady(), and that did the job.
i'm trying to get the coordinates of my kml layer in my android app, and i just cant seem to find how to do it.
i have this kml layer:
KmlLayer layer = new KmlLayer(mMap, R.raw.allowedarea, getApplicationContext());
and i'm trying to get the Latitude and Longtitude list of his boundries points.
ArrayList<LatLnt> latlitArray = layer.soemthing();
could find anything, please guys help.
Try this solution
try {
KmlLayer layer = new KmlLayer(googleMap, R.raw.zone, this);
layer.addLayerToMap();
Iterable<KmlContainer> containers = layer.getContainers();
accessContainers(containers);
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
}
public void accessContainers(Iterable<KmlContainer> containers) {
for (KmlContainer container : containers) {
if (container != null) {
if (container.hasContainers()) {
accessContainers(container.getContainers());
} else {
if (container.hasPlacemarks()) {
accessPlacemarks(container.getPlacemarks());
}
}
}
}
}
public void accessPlacemarks(Iterable<KmlPlacemark> placemarks) {
for (KmlPlacemark placemark : placemarks) {
if (placemark != null) {
KmlGeometry geometry = placemark.getGeometry();
if (geometry instanceof KmlPolygon) {
KmlPolygon polygon = (KmlPolygon) geometry;
mLatLngList.addAll(polygon.getOuterBoundaryCoordinates());
}
}
}
}
This will recursively access every placemark geometry inside the container. I'm not aware if the object obtained can actually be an instance of any other class or collection besides List and LatLng.
public void accessContainers(Iterable<KmlContainer> containers) {
for(KmlContainer c : containers) {
if(c.hasPlacemarks()) {
for(KmlPlacemark p : c.getPlacemarks()) {
KmlGeometry g = p.getGeometry();
Object object = g.getGeometryObject();
if(object instanceof LatLng) {
LatLng latlng = (LatLng)object;
//Do more stuff with the point
}
if(object instanceof List<?>) {
List<LatLng> list = (List<LatLng>)object;
//Do more stuff with the list of points
}
Log.d(TAG, g.getGeometryType() + ":" + object.toString());
}
}
if(c.hasContainers()) {
accessContainers(c.getContainers());
}
}
}
I'm developing an Android app that uses Osmdroid to display the maps in offline mode. I have an issue when I want to zoom in or out by pinching on the map or using the build-in zoomcontrols. When I zoom in the map tiles are not always correctly rendered and when I zoom out the sometimes there are some gray tiles in the map, sometimes everything is rendered OK. It's not related on the location displayed on the map. My map tiles are stored in an osmdroid zip-file with the Mapnik source in the folder /mnt/sdcard/osmdroid. I'm using osmdroid-3.0.7.
So, any help is welcome.
See my code below (my includes aren't included here in the code):
public class MapActivity extends OSMapActivity {
private ArrayList<String[]> mapPointData;
private ArrayList<String[]> multiData;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.map);
setABTitle(getIntent().getExtras().getStringArray("geoLoc")[0]);
actionButtonVisible(getIntent().getExtras().getBoolean("routeList"));
initLayout();
setHomePoint();
}
#Override
protected void onResume() {
super.onResume();
Prefs.clearMapPrefs(this);
}
private void initLayout() {
c = this;
// Buttons # top of the activity
doseeBN = (ImageView) findViewById(R.id.mapDoseeBN);
eatdrinkBN = (ImageView) findViewById(R.id.mapEatdrinkBN);
nightlifeBN = (ImageView) findViewById(R.id.mapNightlifeBN);
sleepBN = (ImageView) findViewById(R.id.mapSleepBN);
// The LinearLayout with the ScrollView for the Subcategories in "Do & See"
doseeLL = (LinearLayout) findViewById(R.id.doseeSubCatLL);
top10BN = (Button) findViewById(R.id.mapDoseeTop10BN);
monumentsBN = (Button) findViewById(R.id.mapDoseeMonumentsBN);
museumBN = (Button) findViewById(R.id.mapDoseeMuseumsBN);
cultureBN = (Button) findViewById(R.id.mapDoseeCultureBN);
attractionsBN = (Button) findViewById(R.id.mapDoseeAttractionBN);
shoppingBN = (Button) findViewById(R.id.mapDoseeShoppingBN);
marketBN = (Button) findViewById(R.id.mapDoseeMarketBN);
// Init of the map an mapcontroller
mapView = (MapView) findViewById(R.id.osmMV);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapController = mapView.getController();
mapController.setZoom(16);
mapView.setUseDataConnection(false);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
// mapView.setDrawingCacheEnabled(true);
mapData = new ArrayList<String[]>();
mapPointData = new ArrayList<String[]>();
multiData = new ArrayList<String[]>();
}
private void setHomePoint() {
//GeoPoint centerPt = new GeoPoint(50.89489, 4.34140); // Point of Grand Place Brussels
homeLat = Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[1]);
homeLong = Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[2]);
GeoPoint centerPt = new GeoPoint(homeLat, homeLong);
if (checkMapRange(Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[1]),
Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[2]))) {
mapController.setCenter(centerPt);
Drawable marker = getResources().getDrawable(R.drawable.ic_pin_marker);
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(new OverlayItem("Here I am!", "Hello", centerPt));
ItemizedOverlay<OverlayItem> itemOverlay =
new ItemizedIconOverlay<OverlayItem>(items, marker, null, new DefaultResourceProxyImpl(this));
mapView.getOverlays().add(itemOverlay);
mapView.invalidate();
} else {
mapController.setCenter(new GeoPoint(50.89489, 4.34140));
mapController.setZoom(11);
Action.alert(this, getResources().getString(R.string.alert_title_notinregion),
getResources().getString(R.string.alert_message_notinregion), false);
mapView.setClickable(false);
}
}
public void onClickMapPointsBN(View v) {
switch(v.getId()) {
case R.id.mapDoseeBN:
setPrefsCategory("DOSEE", doseeBN, "btn_map_dosee", "btn_map_dosee_pressed");
break;
case R.id.mapEatdrinkBN:
setPrefsCategory("EATDRINK", eatdrinkBN, "btn_map_eatdrink", "btn_map_eatdrink_pressed");
break;
case R.id.mapNightlifeBN:
setPrefsCategory("NIGHTLIFE", nightlifeBN, "btn_map_nightlife", "btn_map_nightlife_pressed");
break;
case R.id.mapSleepBN:
setPrefsCategory("SLEEP", sleepBN, "btn_map_sleep", "btn_map_sleep_pressed");
break;
}
setPOIs();
}
public void onClickDoseeListBN(View v) {
switch (v.getId()) {
case R.id.mapDoseeTop10BN:
setDosseSubCat(Definitions.doseeList[0], top10BN);
break;
case R.id.mapDoseeMuseumsBN:
setDosseSubCat(Definitions.doseeList[2], museumBN);
break;
case R.id.mapDoseeCultureBN:
setDosseSubCat(Definitions.doseeList[3], cultureBN);
break;
case R.id.mapDoseeAttractionBN:
setDosseSubCat(Definitions.doseeList[4], attractionsBN);
break;
case R.id.mapDoseeShoppingBN:
setDosseSubCat(Definitions.doseeList[5], shoppingBN);
break;
case R.id.mapDoseeMarketBN:
setDosseSubCat(Definitions.doseeList[6], marketBN);
break;
default:
setDosseSubCat(Definitions.doseeList[1], monumentsBN);
break;
}
setPOIs();
}
private void setPrefsCategory(String cat, ImageView btn, String image, String imageSelected) {
boolean sel = Prefs.getBoolean(this, "map" + cat, false);
Prefs.setBoolean(this, "map" + cat, !sel);
setCategoryImage(btn, image, imageSelected, sel);
if (cat.equalsIgnoreCase("DOSEE")) {
if (sel) {
doseeLL.setVisibility(View.GONE);
} else {
doseeLL.setVisibility(View.VISIBLE);
for (String s : Definitions.doseeList) {
if (s.equals(Definitions.doseeList[1])) {
Prefs.setBoolean(this, "mapDS_" + s, true);
} else {
Prefs.setBoolean(this, "mapDS_" + s, false);
}
}
}
setSubcategoryColor(sel);
}
}
private void setCategoryImage(ImageView btn, String image, String imageSelected, boolean selected) {
String devLang = Prefs.getString(this, "devLanguage", "en");
if (!devLang.equalsIgnoreCase("en")) {
image += "_" + devLang;
imageSelected += "_" + devLang;
}
if (selected) {
btn.setImageResource(this.getResources().getIdentifier(image, "drawable", getPackageName()));
} else {
btn.setImageResource(this.getResources().getIdentifier(imageSelected, "drawable", getPackageName()));
}
}
private void setSubcategoryColor(boolean doseeSelected) {
setDoseeSubCatTextColor(true, top10BN);
setDoseeSubCatTextColor(doseeSelected, monumentsBN);
setDoseeSubCatTextColor(true, museumBN);
setDoseeSubCatTextColor(true, cultureBN);
setDoseeSubCatTextColor(true, attractionsBN);
setDoseeSubCatTextColor(true, shoppingBN);
setDoseeSubCatTextColor(true, marketBN);
}
private void setPOIs() {
mapView.getOverlays().clear();
mapView.invalidate();
mapData.clear();
setHomePoint();
boolean selected;
for (String category : Definitions.categoryList) {
selected = Prefs.getBoolean(this, "map" + category, false);
Log.d("VB.Map", "Category: " + category + " selected: " + selected);
if (selected) {
if (category.equalsIgnoreCase("DOSEE")) {
boolean subSelected;
for (String subcategory : Definitions.doseeList) {
subSelected = Prefs.getBoolean(this, "mapDS_" + subcategory, false);
if (subSelected) {
getSqlData(category, subcategory);
}
}
} else {
getSqlData(category, null);
}
}
}
removeMapDataItems();
//mapPointData = mapData;
//multiDataLocationSelector();
setMapDataPoints();
//setMultiMapPoints();
}
private void getSqlData(String category, String subCategory) {
ArrayList<String[]> sqlData = SqlDB.db.getCategoryItems(Adjust.rewriteCategoryName(category), subCategory);
for (String[] data : sqlData) {
mapData.add(data);
}
}
private void removeMapDataItems() {
for (int i = 0; i < mapData.size(); i++) {
if ((mapData.get(i)[13].equalsIgnoreCase("")) || (mapData.get(i)[14].equalsIgnoreCase(""))) {
mapData.remove(i);
i--;
}
}
}
private void setDosseSubCat(String subCat, Button btn) {
boolean selected = Prefs.getBoolean(this, "mapDS_" + subCat, false);
Prefs.setBoolean(this, "mapDS_" + subCat, !selected);
setDoseeSubCatTextColor(selected, btn);
}
private void setDoseeSubCatTextColor(boolean selected, Button btn) {
if (selected) {
btn.setTextColor(Definitions.colorDoseeSubcat);
} else {
btn.setTextColor(Definitions.colorDoseeSubcatSelected);
}
}
private void setMapDataPoints() {
if (mapData != null) {
ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
OverlayItem overlayItem;
for (String[] item : mapData) {
multiData.add(item);
if (existsInOverlayItems(item, mapOverlays)) {
overlayItem = new OverlayItem("-1", "", new GeoPoint(Float.parseFloat(item[13]), Float.parseFloat(item[14])));
overlayItem.setMarker(getResources().getDrawable(R.drawable.ic_pin_multiple));
} else {
overlayItem = new OverlayItem(item[0], "", new GeoPoint(Float.parseFloat(item[13]), Float.parseFloat(item[14])));
overlayItem.setMarker(getResources().getDrawable(getResources().getIdentifier(item[15], "drawable", getPackageName())));
}
mapOverlays.add(overlayItem);
}
setMapOverlays(mapOverlays);
}
}
private boolean existsInOverlayItems(String[] item, ArrayList<OverlayItem> overlayItemList) {
for (int i = 0; i < overlayItemList.size(); i++) {
if ((new GeoPoint(Double.parseDouble(item[13]), Double.parseDouble(item[14]))).equals(overlayItemList.get(i).mGeoPoint)) {
overlayItemList.remove(i);
return true;
}
}
return false;
}
private void setMapOverlays(ArrayList<OverlayItem> overlays) {
ItemizedOverlay<OverlayItem> itemOverlays = new ItemizedIconOverlay<OverlayItem>(
overlays, getResources().getDrawable(R.drawable.ic_pin_marker), new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
public boolean onItemLongPress(int arg0, OverlayItem item) {
mapOverlayItemPressed(Integer.parseInt(item.mTitle), item);
return false;
}
public boolean onItemSingleTapUp(int arg0, OverlayItem item) {
mapOverlayItemPressed(Integer.parseInt(item.mTitle), item);
return false;
}
}, new DefaultResourceProxyImpl(this));
mapView.getOverlays().add(itemOverlays);
mapView.invalidate();
}
private void mapOverlayItemPressed(int itemId, OverlayItem overlayItem) {
if (itemId == -1) {
Collect.multiPOIList.clear();
for (String[] item : multiData) {
if ((new GeoPoint(Double.parseDouble(item[13]), Double.parseDouble(item[14]))).equals(overlayItem.mGeoPoint)) {
Collect.multiPOIList.add(item);
}
}
Action.alertWithListView(this, getResources().getString(R.string.alert_title_multiplepoi), false);
} else {
SqlDB.db.getItemsById(itemId);
Bundle b = new Bundle();
b.putInt("listSelection", 0);
Action.newIntent(c, DetailActivity.class, b);
}
}
private boolean checkMapRange(double lat, double lng) {
double mapLatMax = 50.922085;
double mapLatMin = 50.781631;
double mapLongMin = 4.240723;
double mapLongMax = 4.490662;
if ((lat > mapLatMin) && (lat < mapLatMax)) {
if ((lng > mapLongMin) && (lng < mapLongMax)) {
return true;
}
}
return false;
}
}
And here the code of the OSMapActivity:
public class OSMapActivity extends ActionbarActivity {
protected Context c;
protected MapView mapView;
protected MapController mapController;
protected ArrayList<String[]> mapData;
protected ImageView doseeBN;
protected ImageView eatdrinkBN;
protected ImageView nightlifeBN;
protected ImageView sleepBN;
protected LinearLayout doseeLL;
protected Button top10BN;
protected Button monumentsBN;
protected Button museumBN;
protected Button cultureBN;
protected Button attractionsBN;
protected Button shoppingBN;
protected Button marketBN;
protected double homeLat;
protected double homeLong;
public void onClickABActionButton(View v) {
boolean actionButton = Prefs.getBoolean(this, "abActionButtonRoute", false);
if (actionButton) {
// TODO Add with current location => location manager in separate class
/*GPS.init(this);
GPS.enableGPSProvider();
GPS.enableNetworkProvider();
//Action.loadApp(this, Intent.ACTION_VIEW, Uri.parse("geo:50.89489,4.34140?daddr=Heiveld+21+Opwijk"));
Action.loadApp(this, Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" + GPS.latitude + "," + GPS.longitude
+ "&daddr=Heiveld+21+1745+Opwijk"));
GPS.stop();*/
Action.loadMapsWithMyLocation(this, homeLat, homeLong);
} else {
Collect.dbList.clear();
for (String[] data : mapData) {
Collect.dbList.add(data);
}
// TODO Load new intent with list
Action.newIntent(this, MapListActivity.class, null);
}
}
}
Thanks for your help.
Kr
I raised an issue on version 3.0.6 about this. In the comments the authors say it was fixed on Feb 1st. As the 3.0.7 jar is dated Jan 29, I assume the fix isn't in it. I'm sticking with version 3.0.5 for now, although the cycle maps don't work in it and the tile loading can be a bit flickery. If your maps are offline though, they should load pretty fast and flicker might not be an issue.
I'm not 100% sure if this is the same problem as reported here:
OSMDroid Google Group
If so then the solution (for now) seems to be to download the current OSMDroid source and build your own .jar library.
No changes to the source are required BUT the tile loading problem is fixed.