MyLocationOverlay problem

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

MyLocationOverlay problem

Postby drogus » Sun May 31, 2009 8:49 am

Hi,

I've created simple android app and would like to add MyLocationOverlay to the map. My code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.    public void onCreate(Bundle savedInstanceState) {
  3.  
  4.         super.onCreate(savedInstanceState);
  5.  
  6.         setContentView(R.layout.main);
  7.  
  8.         linearLayout = (LinearLayout) findViewById(R.id.zoomview);
  9.  
  10.         mapView = (MapView) findViewById(R.id.mapview);
  11.  
  12.         mapController = mapView.getController();
  13.  
  14.         mapOverlays = mapView.getOverlays();
  15.  
  16.         mapView.setBuiltInZoomControls(true);
  17.  
  18.        
  19.  
  20.         myLocation = new MyLocationOverlay(this, mapView);
  21.  
  22.        
  23.  
  24.         myLocation.enableMyLocation();
  25.  
  26.         mapOverlays.add(myLocation);
  27.  
  28.        
  29.  
  30.         //myLocation.enableCompass();
  31.  
  32.        
  33.  
  34.         myLocation.runOnFirstFix(new Runnable() {
  35.  
  36.             public void run() {
  37.  
  38.                 mapController.animateTo(myLocation.getMyLocation());
  39.  
  40.             }
  41.  
  42.         });
  43.  
  44.     }
  45.  
  46.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


my location overlay is not shown on the map and I don't know what's going on... I've set latitude and longitude with emulator console and it shows proper location in "Maps" app provided with android. Sorry for such a lame question, but I really can't figure it out.
drogus
Freshman
Freshman
 
Posts: 4
Joined: Sun May 31, 2009 8:29 am

Top

Postby drogus » Thu Jun 04, 2009 1:48 pm

If there is no ideas maybe someone could just paste his working code?
drogus
Freshman
Freshman
 
Posts: 4
Joined: Sun May 31, 2009 8:29 am

Postby iifuzz » Thu Jun 04, 2009 2:10 pm

Global

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. GeoPoint point;
  2.  
  3. LocationManager locationManager;
  4.  
  5.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



In OnCreate
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.         locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  5.  
  6.         locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  7.  
  8.         locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1l, 5, this);
  9.  
  10.        
  11.  
  12.  
  13.  
  14.         MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
  15.  
  16.         List<Overlay> list = mapView.getOverlays();
  17.  
  18.         list.add(myLocationOverlay);
  19.  
  20.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.         @Override
  5.  
  6.         public void onLocationChanged(Location location) {
  7.  
  8.  
  9.  
  10.                 if (location != null) {
  11.  
  12.  
  13.  
  14.                        
  15.  
  16.                 Double lat = location.getLatitude()*1E6;
  17.  
  18.                 Double lng = location.getLongitude()*1E6;
  19.  
  20.                
  21.  
  22.                 point = new GeoPoint(lat.intValue(), lng.intValue());
  23.  
  24.                 mapController.setCenter(point);
  25.  
  26.  
  27.  
  28.  
  29.  
  30.                 }
  31.  
  32.                                
  33.  
  34.         }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.         @Override
  41.  
  42.         public void onProviderDisabled(String provider) {
  43.  
  44.                 // TODO Auto-generated method stub
  45.  
  46.                
  47.  
  48.         }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.         @Override
  55.  
  56.         public void onProviderEnabled(String provider) {
  57.  
  58.                 // TODO Auto-generated method stub
  59.  
  60.                
  61.  
  62.         }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.         @Override
  69.  
  70.         public void onStatusChanged(String provider, int status, Bundle extras) {
  71.  
  72.                 // TODO Auto-generated method stub             
  73.  
  74.         }
  75.  
  76.        
  77.  
  78.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4





Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         protected class MyLocationOverlay extends com.google.android.maps.Overlay {
  2.  
  3.                
  4.  
  5.                 @Override
  6.  
  7.                 public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
  8.  
  9.                        
  10.  
  11.                         super.draw(canvas, mapView, shadow);
  12.  
  13.  
  14.  
  15.                         Paint paint = new Paint();     
  16.  
  17.                         Point myScreenCoords = new Point();
  18.  
  19.  
  20.  
  21.                         mapView.getProjection().toPixels(point, myScreenCoords);
  22.  
  23.  
  24.  
  25.                         paint.setStrokeWidth(1);
  26.  
  27.                         paint.setARGB(255, 255, 255, 255);
  28.  
  29.                         paint.setStyle(Paint.Style.
  30.  
  31.  
  32.  
  33.  
  34.  
  35.                         Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.gpscar);
  36.  
  37.                        
  38.  
  39.                        
  40.  
  41.  
  42.  
  43.                         canvas.drawBitmap(bmp, myScreenCoords.x - bmp.getWidth() / 2, myScreenCoords.y - bmp.getHeight() / 2, paint);
  44.  
  45.  
  46.  
  47.  
  48.  
  49.                         return true;
  50.  
  51.  
  52.  
  53.                 }
  54.  
  55.         }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
iifuzz
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu May 21, 2009 6:00 pm

Postby drogus » Thu Jun 04, 2009 3:03 pm

iifuzz: Is it code for 1.1 API version? MyLocationOverlay is declared in your code. In 1.5 which I've started to use, there is MyLocationOverlay provided already...

If I'm not wrong and this is older version, does anyone has working code for 1.5 API?
drogus
Freshman
Freshman
 
Posts: 4
Joined: Sun May 31, 2009 8:29 am

Postby iifuzz » Thu Jun 04, 2009 3:10 pm

this is for 1.5
i did it yesturday :o
iifuzz
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu May 21, 2009 6:00 pm

Postby drogus » Thu Jun 04, 2009 3:23 pm

iifuzz wrote:this is for 1.5
i did it yesturday :o


ok :)

But I'm wondering how to use this: http://code.google.com/android/add-ons/ ... erlay.html

I like using code provided by API, but I can't get it work...
drogus
Freshman
Freshman
 
Posts: 4
Joined: Sun May 31, 2009 8:29 am

Top

Postby ptucker » Sun Jul 05, 2009 10:27 pm

I've had similar problems. Banged my head against it for a whole day before giving up.
ptucker
Freshman
Freshman
 
Posts: 4
Joined: Wed Jun 10, 2009 5:05 pm

Try this...

Postby pnguin34 » Thu Oct 01, 2009 2:22 am

After adding the MyLocationOverlay to the mapView, do this:

mapView.postInvalidate();

Worked for me.

- dave
pnguin34
Freshman
Freshman
 
Posts: 2
Joined: Thu Oct 01, 2009 2:19 am

MyLocationOverlay

Postby toanchinh » Sat Nov 14, 2009 5:45 pm

private void controlMyLocation()
{
myLocationOverlay = new My_LocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);

myLocationOverlay.runOnFirstFix(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
move_Map(myLocationOverlay.getMyLocation());
}
});
}

private void move_Map(GeoPoint geoPoint_myLocation) {
if(geoPoint_myLocation != null)
{
mapView.getController().animateTo(geoPoint_myLocation);
mapView.getController().setZoom(15);
}
}
toanchinh
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Aug 26, 2009 5:18 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 4 guests