GPS를 이용해서 역지오 코딩 하는 법을 알고 싶습니다.
조회수 925회
GPS를 이용해서 위도와 경도를 찾는거 까지는 됬는데 역지오 코딩으로 그 찾은 위도 경도를 주소로 변환해서 보고 싶은데 어떻게 적용하는지 모르겠어서 물어봅니다.
JAVA 소스 입니다.
package com.example.user.gpstest2;
import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
TextView tv;
ToggleButton tb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
tv = (TextView) findViewById(R.id.textView2);
tv.setText("위치정보 미수신중");
tb = (ToggleButton)findViewById(R.id.toggle1);
final LocationManager lm = (LocationManager) getSystemService( Context.LOCATION_SERVICE);
tb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
if(tb.isChecked()){
tv.setText("수신중..");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, mLocationListener);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 100, 1, mLocationListener);
}else{
tv.setText("위치정보 미수신중");
lm.removeUpdates(mLocationListener);
}
}catch(SecurityException ex){
}
}
});
} // end of onCreate
private final LocationListener mLocationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.d("test", "onLocationChanged, location:" + location);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
double altitude = location.getAltitude();
float accuracy = location.getAccuracy();
String provider = location.getProvider();
tv.setText("위치정보 : " + provider + "\n위도 : " + longitude + "\n경도 : " + latitude
+ "\n고도 : " + altitude + "\n정확도 : " + accuracy);
}
public void onProviderDisabled(String provider) {
Log.d("test", "onProviderDisabled, provider:" + provider);
}
public void onProviderEnabled(String provider) {
Log.d("test", "onProviderEnabled, provider:" + provider);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("test", "onStatusChanged, provider:" + provider + ", status:" + status + " ,Bundle:" + extras);
}
};
}
XML 소스 입니다.
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GPS 에 수신된 현재위치"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="결과창"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ToggleButton
android:id="@+id/toggle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="위치정보수신시작"
android:textOn="위치정보수신종료"/>
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력