如何在每次用户更改位置时使用toast通知

时间:2013-01-16 08:39:16

标签: location toast

我想在每次用户更改位置时通知用户。我已在onLocationChanged内插入吐司,但makeText上的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());


    }}

  }

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

相关问题