나는 여기에 가이드를 따라 해요 : 나는 단순히 장치의 GPS 좌표를 취득하는 안드로이드 응용 프로그램을 화면에 표시하기 위해 노력하고있어 http://www.firstdroid.com/2010/04/29/android-development-using-gps-to-get-current-location-2/표시 GPS 위치 - 안드로이드
. telnet으로 "geo fix 30.0 30.0"을 입력하면 내 코드가 에뮬레이터에서 잘 작동하지만, 내 전화에서이 코드를 사용하면 절대 좌표를 얻지 못합니다. 지도를 열었을 때 내 GPS가 정상적으로 작동합니다. 정확한 위치가 표시됩니다. 그래서 뭔가를 다음 코드로 잘못해야합니다 : 여기
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
public class BusAppActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
}
/* To test in the emulator, use the telnet commands:
* telnet localhost 5554
* geo fix 30.0 30.0 */
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
TextView tv = (TextView) findViewById(R.id.textview);
@Override
public void onLocationChanged(Location loc){
Log.d("tag", "Finding Latitude");
double lat = loc.getLatitude();
Log.d("tag", "Lat: "+String.valueOf(lat));
Log.d("tag", "Finding Longitude");
double lon = loc.getLongitude();
Log.d("tag", "Lon: "+String.valueOf(lon));
String Text = "My current location is: " +
"\nLatitude = " + lat +
"\nLongitude = " + lon;
// Display location
tv.setText(Text);
}
@Override
public void onProviderDisabled(String provider){
Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider){
Toast.makeText(getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){
}
}
}
내 매니페스트 :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gsingh.busapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".BusAppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
너무 많은 문제가, 누군가가이 프로젝트를 구축하고 자신의 휴대 전화에 그것을 시도 할 수 아니에요 어쩌면 경우? 추가 할 필요가있는 것은 "textview"에 유일한 텍스트 뷰어를 표시하는 것뿐입니다.
매니페스트에 다음 행이 있습니까? ? –
NickT
예, 있습니다. 게시물에 추가하겠습니다. 그 줄이 없다면 에뮬레이터가 작동했는지 모르겠다. – gsingh2011
실제 전화에서 오류가 발생하거나 위치 업데이트가 없습니까? 휴대 전화 (GPS 및 네트워크 위치)에 제대로 설정되었는지 확인하고 DONT에 비행기 모드가 설정되어 있는지 확인하십시오. – Jack