Itemized overlay problem.

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Itemized overlay problem.

Postby jonbonazza » Thu Jan 06, 2011 8:00 pm

Ok, so I have an app that reads in GPS data from a file and outputs it on a map. It's reading the data fine, but a few problems arise when plotting:

1) It doesn't plot anything until I tap the screen.

2) Although all of the coordinates are within a few feet from eachother, it only seems to be displaying one graphic.



Any ideas on these?

I suppose number 2 could be related to the fact that the points are so close. If this is the case, is there a way around this? Also, I should note that I tried zooming in all of the way, but it still only shows 1 point... shouldn't there at least be more when zoomed in closely? Or perhaps I am not creating the overlays correctly.

Here are some code snippets:

MapItemizedOverlay.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MapItemizedOverlay extends ItemizedOverlay
  2. {
  3.         //Initialize an array list of overlay items
  4.         private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
  5.         Context mContext;
  6.        
  7.         public MapItemizedOverlay(Drawable defaultMarker)
  8.         {
  9.                 super(boundCenterBottom(defaultMarker));
  10.         }
  11.         public MapItemizedOverlay(Drawable defaultMarker, Context context)
  12.         {
  13.                 super(defaultMarker);
  14.                 mContext = context;
  15.         }
  16.  
  17.         //Method to return the number of overlays
  18.         @Override
  19.         public int size()
  20.         {
  21.                 return mOverlays.size();
  22.         }
  23.        
  24.         //Method to add an overlay item to the array list of overlays
  25.         public void addOverlay(OverlayItem overlay)
  26.         {
  27.                 mOverlays.add(overlay);
  28.                 populate();
  29.         }
  30.        
  31.         //Method to create an overlay item
  32.         @Override
  33.         protected OverlayItem createItem(int i)
  34.         {
  35.                 return mOverlays.get(i);
  36.         }
  37.        
  38.         @Override
  39.         protected boolean onTap(int index)
  40.         {
  41.                 OverlayItem item = mOverlays.get(index);
  42.                 GeoPoint point = item.getPoint();
  43.                 //(...)
  44.                 return true;
  45.         }
  46.        
  47.         public void removeOverlay(OverlayItem overlay)
  48.         {
  49.                 mOverlays.remove(overlay);
  50.                 populate();
  51.         }
  52.  
  53. }
  54.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


plotfix() method:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private MapItemizedOverlay itemizedOverlay;
  3. private List<Overlay> mapOverlays;
  4.  
  5.  
  6. private void plotFix(String msg)
  7.         {
  8.                 //Initialize the temporary string
  9.                 String line = convertEOL(msg);
  10.                
  11.                
  12.                 //Create delimiters
  13.                 int longEnd = line.indexOf(",");
  14.                 int latEnd = line.indexOf(",", longEnd);
  15.                 latEnd += longEnd;
  16.                
  17.                 //Split string into separate entities
  18.                 String longitude = line.substring(0, longEnd);
  19.                 String latitude = line.substring(longEnd + 1, latEnd);
  20.                
  21.                 //Convert separated strings into double
  22.                 double dblLongitude = Double.parseDouble(longitude);
  23.                 double dblLatitude = Double.parseDouble(latitude);
  24.                
  25.                 //Convert from micro-degrees to degrees
  26.                 dblLongitude *= 1000000.0;
  27.                 dblLatitude *= 1000000.0;
  28.                
  29.                 //Convert degrees into integer values
  30.                 int intLong = (int)dblLongitude;
  31.                 int intLat = (int)dblLatitude;
  32.                
  33.                
  34.                 //Convert degrees into Geographical points
  35.                 GeoPoint point = new GeoPoint(intLat, intLong);
  36.                
  37.                 //Create new overlay item from the point
  38.                 OverlayItem item = new OverlayItem(point, null, null);
  39.                
  40.                 //Add the overlay item to the itemized overlay
  41.                 itemizedOverlay.addOverlay(item);
  42.                 //Alter the GPSLabel's text
  43.                 mapOverlays.add(itemizedOverlay);
  44.                
  45.         }
  46.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Re: Itemized overlay problem.

Postby jonbonazza » Thu Jan 06, 2011 9:07 pm

Ok, so I got that working I think, but now I have another problem. When reading the file, it has problems converting string to double on the 3rd line. The weird thing is that the second line is identical... why would the second line work and the 3rd not work? O.o
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Itemized overlay problem.

Postby jonbonazza » Fri Jan 07, 2011 5:52 am

I figured it out. Stupid mistake.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests