I've been able to find latitude and longitude using GPS, but I want to convert the latitude and longitude found into an address through reverse geocoding, but I'm asking because I don't know how to apply it.
This is JAVA source.
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 ("location information not received");
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 ("Incoming...");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, mLocationListener);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 100, 1, mLocationListener);
}else{
TV.setText ("location information not received");
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("Location information:" + provider +"\nlatitude:" + longitude +"\nlatitude:" + latitude
+ "\nAdvanced:" + altitude +"\nAccuracy:" + acuity);
}
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 source.
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current location received on GPS"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Results pane"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ToggleButton
android:id="@+id/toggle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Start receiving location information"
android:textOn="End of receiving location information"/>
Reverse geocoding is It is possible through the API that is currently being serviced by each Vender.
There is Naver/Kakao API for domestic service in Korea Google also has a reverse geocoding API, but I don't know if the search results come out in Korean.
It's a simple REST GET request It's normal to send a gastric hardness with a parameter.
© 2024 OneMinuteCode. All rights reserved.