0

每次用户更改位置时,我想通知用户。我在里面插入了烤面包,onLocationChanged但是在makeTextfrom上有一条红线toast.makeText。它说

The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (CurrentLocationOverlay, String, int)

然后我从

Toast.makeText(this,"Your current speed is :" +gps.getSpeed, Toast.LENGTH_SHORT).show()

Toast.makeText(getBaseContext(),"Your current speed is :" +gps.getSpeed, Toast.LENGTH_SHORT).show().

然后它告诉我创建getBaseContext()方法。我什至把它改成了getApplicationContext(). 还是一样的答案。甚至改成类名还是一样

公共类 CurrentLocationOverlay 扩展 MyLocationOverlay {

GPSTracker gps;



  @Override
  public synchronized void onLocationChanged(Location location) {
    super.onLocationChanged(location);

    Toast.makeText(this,"Your current speed is :" +gps.getSpeed(), 
              Toast.LENGTH_SHORT).show();




    // only move to new position if enabled and we are in an border-area
    if (mc != null && centerOnCurrentLocation && inZoomActiveArea(currentPoint)) {
      mc.animateTo(getMyLocation());


    }}

  }
4

2 回答 2

0

我很确定当类扩展 Activity 时可以使用 getApplicationContext 和 getBaseContext。

是否可以扩展 Activity 并实现 MyLocationOverlay?

于 2013-04-07T16:45:31.957 回答
0

具体方法需要扩展Activity,然后才能实现getApplicationContect。

于 2014-11-16T20:44:53.757 回答