2012-04-29 9 views
2

私はしばらくの間このコードを作業していましたが、すべてが大丈夫ですが、私のエディタであるEclipseはmyManagerをキャストするようにとどめています。コードは次のとおりです。GPS現在地

package com.gps.project; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.TextView; 
import android.content.Context; 
import android.widget.Button; 
/*LOcation based API*/ 
import android.location.LocationManager; 


public class GpsActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     /*Create ab ttuon we are to use in our GPS*/ 
     final Button gpsButton=(Button) findViewById(R.id.gpsButton); 
     gpsButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       LoadCoords(); 

      } 
     }); 

    } 
    public void LoadCoords(){ 
     /*Create two textfields that will contain information as latitudes and longitudes*/ 
     TextView latText=(TextView) findViewById(R.id.latText); 
     TextView lngText=(TextView) findViewById(R.id.lngText); 

     /*Creation of a location manager from which we are to pull the location values*/ 
     LocationManager myManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     /*To pull the coordinates from myManager, we use the getCurrentLocation() method.*/ 
     Double latPoint = myManager.getCurrentLocation("gps").getLatitude(); 
     Double lngPoint = myManager.getCurrentLocation("gps").getLongitude(); 
     /*Finally, take the new Double values and pass them to your TextViews:*/ 
     latText.setText(latPoint.toString()); 
     lngText.setText(lngPoint.toString()); 
    } 
} 

誰かが私のエラーを修正するのを助けてくれたらうれしいです。私は経度と緯度を取得するつもりです。

+0

うーん、私は 'getCurrentLocation'inを見つけることができなかった' LocationManager'httpのインスタンスメソッドandroid/location/LocationManager.html 「getLastKnownLocation」と思ってください。 –

+0

私の回答は役に立ちましたか? +1して受け入れることを忘れないでください、その場合は、ありがとう:) –

答えて

0

私が返信で言ったように、私はドキュメントで見つけられなかったgetCurrentLocationgetLastKnownLocation insteand(おそらく非難される)を使用しているべきだと思います。

与えられたプロバイダから取得した最後の既知の場所 修正からのデータを示す場所を返します。これは、 プロバイダーを開始せずに行うことができます。このデバイスの電源を切って別の の場所に移動した場合、この場所は古くなっている可能性があります(例: )。プロバイダが現在無効な場合、nullが返されます。あなたが追加する必要が

permissionは次のとおりです。//developer.android.com/reference/:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
+0

Thanx。そのhelped.just私のマニフェストXMLファイルで追加する必要がありますどのようなアクセス許可をちょうど。 – user1364687

+0

私は適切な許可で私の答えを編集しました。 –

+0

Thanx。私はちょうど別の質問をアップロードしたリモートWebサイトにデータをアップロード.....と、あなたはあなたが助けになることができると思いますか? – user1364687

関連する問題