Navigation Path on Map & Printing Map

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

Navigation Path on Map & Printing Map

Postby idiot2k1 » Mon Aug 30, 2010 5:58 pm

I am working on an app that will track the user and display a path on the mapview to show where they have been.

I have the map working and I can create overlays on the map as well, but I wanted to know what the best practice would be to create a path.

Would it be ok to have a service run and every two seconds or so create a new blip on the map using the overlay? How many overlays can be on a map before the processor starts to chug?

I also need to print the map and completed path out after the user finishes the route. What would be the best way to do that?

Thanks Much,
Adam
idiot2k1
Freshman
Freshman
 
Posts: 9
Joined: Wed Jul 14, 2010 2:58 am

Top

Re: Navigation Path on Map & Printing Map

Postby Vish0306 » Tue Aug 31, 2010 2:33 pm

Hi Adam,

can you send me your code so that i can try to resolve your issue.
Regards:
SEVish
Vish0306
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Feb 18, 2010 5:59 pm
Location: India

Re: Navigation Path on Map & Printing Map

Postby idiot2k1 » Tue Aug 31, 2010 6:30 pm

The code I have for the blips on the map and getting the GPS location are as follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void blipMap(){
  2.  
  3.                 Log.d(TAG, "Blipping Map");
  4.                 double[] curr = getGPS();
  5.                 Double userLat = curr[0];
  6.                 Double userLong = curr[1];
  7.            
  8.                 Drawable dot = this.getResources().getDrawable(R.drawable.dot);
  9.                                
  10.             HaulItemizedOverlay itemizedoverlay = new HaulItemizedOverlay(dot);
  11.             GeoPoint userPt = new GeoPoint(userLat.intValue(),userLong.intValue());
  12.             //GeoPoint userPt = whereamI.getMyLocation();
  13.             OverlayItem overlayitemuser = new OverlayItem(userPt, "", "");
  14.             itemizedoverlay.addOverlay(overlayitemuser);
  15.                 mapOverlays.add(itemizedoverlay);
  16.                 mapView.postInvalidate();
  17.                
  18.         }
  19.         private double[] getGPS() {  
  20.  
  21.                 LocationManager lm;
  22.                 Location l = new Location(TAG);
  23.                 lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);  
  24.             List<String> providers = lm.getProviders(true);  
  25.            
  26.             /* Loop over the array backwards, and if you get an accurate location, then break out the loop*/  
  27.             l = null;  
  28.                
  29.             for (int i=providers.size()-1; i>=0; i--) {  
  30.                 l = lm.getLastKnownLocation(providers.get(i));  
  31.                 if (l != null) break;  
  32.             }  
  33.                
  34.             double[] gps = new double[2];  
  35.             if (l != null) {  
  36.                 gps[0] = l.getLatitude()*1000000;  
  37.                 gps[1] = l.getLongitude()*1000000;  
  38.             }  
  39.            
  40.             return gps;  
  41.         }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


I assume drawing a point would be better than overlaying an image for the dot?
idiot2k1
Freshman
Freshman
 
Posts: 9
Joined: Wed Jul 14, 2010 2:58 am

Re: Navigation Path on Map & Printing Map

Postby idiot2k1 » Wed Sep 01, 2010 4:56 pm

So I changed my code a little bit:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void blipMap(){
  2.  
  3.                 Log.d(TAG, "Blipping Map");
  4.            
  5.                 Drawable dot = getResources().getDrawable(R.drawable.dot);
  6.                
  7.             HaulItemizedOverlay itemizedoverlay = new HaulItemizedOverlay(dot);
  8.  
  9.             if(whereamI.getMyLocation()!=null){
  10.                     OverlayItem overlayitemuser = new OverlayItem(whereamI.getMyLocation(), "", "");
  11.                     itemizedoverlay.addOverlay(overlayitemuser);
  12.                         mapOverlays.add(itemizedoverlay);
  13.                         mapView.postInvalidate();
  14.             }
  15.         }
  16.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


This creates a blip using a drawable resource file that follows the user's whereamI MyLocationOverlay location. How would I create a single point instead of my dot resource file? I think the Android drawing point would look / scale better than my dot.

Also, would it be easy to draw a line between the last point and the current point (maybe have the last point x and y be a global variable that gets changed every time the map is blipped?)

Thanks
-Adam
idiot2k1
Freshman
Freshman
 
Posts: 9
Joined: Wed Jul 14, 2010 2:58 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 5 guests