package com.ForHappyDate.AcessLocation;
import java.util.Hashtable;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
public class AcessLocation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = ( LocationManager ) getSystemService( Context.LOCATION_SERVICE );
Location l = lm.getLastKnownLocation( LocationManager.GPS_PROVIDER );
TextView tv = ( TextView ) findViewById( R.id.test );
Hashtable< String, Double > h = updateWithNewLocation( l );
if( h != null ) {
String text = h.get( "lat" ) + h.get( "lng" ) + "";
tv.setText( text );
}
else {
System.out.println( "null" );
}
}
private Hashtable updateWithNewLocation( Location l ) {
Hashtable< String, Double > result = new Hashtable< String, Double >();
if( l != null ) {
double lat = l.getLatitude();
double lng = l.getLongitude();
result.put( "lat", lat );
result.put( "lng", lng );
}
else {
return null;
}
return result;
}
}
간단한 gps예제입니다.
Location이 자꾸 널이 되는데 왜 그런지 모르겠습니다.
갤럭시s에서 테스트를 해보았는데 null이 됩니다. 집밖에서 해봐도 그렇고
퍼미션도 다해줬습니다.
왜 널이 뜨죠?
갤S의 경우, TMAP를 실행 시킨 후 맵뷰화면에서, GPS Icon이 녹색으로 변하면, 3D Fix가 된 상태입니다.
TMAP종료 후 한번 해보시면 될지도 모르겠네요.