Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to show location pin of the visible portion of a mapview in android?
    primarykey
    data
    text
    <p>Here is my <code>asynctask</code> part where I am putting pin in some location parsed from an xml. This is doing fine for a small location data set but takes a long time when the location data set is large.</p> <pre><code>private class MapLoader extends AsyncTask&lt;Void, Void, Void&gt; { ProgressDialog dialog; ArrayList&lt;POI&gt;[] mappoiList; @Override protected void onPreExecute() { mapOverlays = mapview.getOverlays(); dialog = new ProgressDialog(MainActivity.this); dialog.show(); } @Override protected Void doInBackground(Void... params) { // TODO Auto-generated method stub try { URL url = new URL(MainActivity.baseUrl + "latitude=40.9192799&amp;longitude=-74.0657508&amp;distance=20"); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); ParserHandler parserHandler = new ParserHandler(); xr.setContentHandler(parserHandler); xr.parse(new InputSource(url.openStream())); Log.d("Thread", url.toString()); basicItems = parserHandler.getBasicItems(); featuredItems = parserHandler.getFeaturedItems(); restaurants = parserHandler.getRestaurants(); mapvisibleList = new ArrayList&lt;POI&gt;(); mappoiList = new ArrayList[2]; mappoiList[0] = new ArrayList&lt;POI&gt;(); mappoiList[1] = new ArrayList&lt;POI&gt;(); for (int i = 0; i &lt; featuredItems.size(); i++) { POI poi = new POI(featuredItems.get(i), 1); mappoiList[0].add(poi); } for (int i = 0; i &lt; restaurants.size(); i++) { POI poi = new POI(restaurants.get(i), 2); mappoiList[0].add(poi); } for (int i = 0; i &lt; basicItems.size(); i++) { POI poi = new POI(basicItems.get(i), 0); mappoiList[1].add(poi); } for (int i = 0; i &lt; mappoiList[0].size(); i++) { if (mappoiList[0] != null) { mapvisibleList.add(mappoiList[0].get(i)); } } for (int i = 0; i &lt; mappoiList[1].size(); i++) { if (mappoiList[1] != null) { mapvisibleList.add(mappoiList[1].get(i)); } } for (FeaturedItem item : featuredItems) { Log.d("FEATURED", item.getName() + "Distance: " + item.getDistance()); } for (Restaurant item : restaurants) { Log.d("RESTAURANTS", item.getName() + "Distance: " + item.getDistance()); } for (BasicItem item : basicItems) { Log.d("BASIC", item.getName() + "Distance: " + item.getDistance()); } } catch (MalformedURLException e) { e.printStackTrace(); showErrorDialog("Error", "Malformed URL Error Occurred"); } catch (ParserConfigurationException e) { e.printStackTrace(); showErrorDialog("Error", "Parser Configuration Problem Occurred"); } catch (SAXException e) { e.printStackTrace(); showErrorDialog("Error", "SAX Parser Error Occurred"); } catch (IOException e) { e.printStackTrace(); showErrorDialog("Error", "IOException Occurred"); } catch (Exception e) { e.printStackTrace(); } GlobalData.gBasicItems = basicItems; GlobalData.gFeaturedItems = featuredItems; GlobalData.gRestaurants = restaurants; if (currentLocation != null) { int curLat = (int) (currentLocation.getLatitude() * 1e6); int curLon = (int) (currentLocation.getLongitude() * 1e6); GeoPoint gp = new GeoPoint(curLat, curLon); mapControl.animateTo(gp); mapControl.setZoom(14); OverlayItem item = new OverlayItem(gp, "My Location", "My Location"); itemizedOverlay1 = new MyItemizedOverlay(drawableFeature, MainActivity.this, mappoiList[0]); itemizedOverlay2 = new MyItemizedOverlay(drawableBasic, MainActivity.this, mappoiList[1]); itemizedOverlay3 = new MyItemizedOverlay(drawableCurrent, MainActivity.this, mappoiList[0]); Log.i("asyncbasic", "" + basicItems.size()); Log.i("asyncfeatured", "" + featuredItems.size()); Log.i("asyncres", "" + restaurants.size()); if (featuredItems != null) { int featuredLength = featuredItems.size(); for (int i = 0; i &lt; featuredLength; i++) { FeaturedItem fItem = featuredItems.get(i); int lat = (int) (Double .parseDouble(fItem.getLatitude()) * 1e6); int lon = (int) (Double.parseDouble(fItem .getLongitude()) * 1e6); OverlayItem oItem = new OverlayItem(new GeoPoint(lat, lon), fItem.getName(), "Feature"); itemizedOverlay1.addOverlay(oItem); Log.i("Map over lay", "Finished one featured"); } } if (basicItems != null) { int basicLength = basicItems.size(); for (int i = 0; i &lt; basicLength; i++) { BasicItem bItem = basicItems.get(i); int lat = (int) (Double .parseDouble(bItem.getLatitude()) * 1e6); int lon = (int) (Double.parseDouble(bItem .getLongitude()) * 1e6); OverlayItem oItem = new OverlayItem(new GeoPoint(lat, lon), bItem.getName(), "Basic"); itemizedOverlay2.addOverlay(oItem); Log.i("Map over lay", "Finished one Basic"); } } if (restaurants != null) { int resLength = restaurants.size(); for (int i = 0; i &lt; resLength; i++) { Restaurant res = restaurants.get(i); int lat = (int) (Double.parseDouble(res.getLatitude()) * 1e6); int lon = (int) (Double.parseDouble(res.getLongitude()) * 1e6); OverlayItem oItem = new OverlayItem(new GeoPoint(lat, lon), res.getName(), "Restaurant"); itemizedOverlay1.addOverlay(oItem); Log.i("Map over lay", "Finished one Restaurant"); } } itemizedOverlay3.addOverlay(item); } return null; } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub mapOverlays.clear(); mapOverlays.add(itemizedOverlay1); mapOverlays.add(itemizedOverlay2); mapOverlays.add(itemizedOverlay3); mapview.postInvalidate(); dialog.dismiss(); } } </code></pre> <p>I learned about using <code>getLatitudeSpan</code> and <code>getLongitudeSpan</code> to get rid of this problem, but I am not too clear on where and how to use it in my async task. Any suggestions ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload