Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.location;
- import java.io.IOException;
- import java.util.*;
- import android.widget.*;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.Bundle;
- import android.os.Handler;
- import android.location.*;
- import android.content.*;
- public class LocationActivity extends Activity {
- Button addressButton;
- TextView locationText;
- TextView addressText;
- Location currentLocation;
- double currentLatitude;
- double currentLongitude;
- ProgressDialog progressDialog = null;
- Handler mHandler = new Handler()
- {
- public void handleMessage(android.os.Message msg)
- {
- super.handleMessage(msg);
- switch (msg.what)
- {
- case 10:
- progressDialog.dismiss();
- break;
- }
- }
- };
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main2);
- addressText = (TextView)findViewById(R.id.addressText);
- locationText = (TextView)findViewById(R.id.locationText);
- // addressButton = (Button)findViewById(R.id.addressButton);
- this.addressText.setText("ready");
- LocationManager locationManager =
- (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
- LocationListener locationListener = new LocationListener() {
- public void onLocationChanged(Location location) {
- currentLocation = location;
- currentLatitude = currentLocation.getLatitude();
- currentLongitude = currentLocation.getLongitude();
- locationText.setText(currentLatitude + ", " + currentLongitude);
- }
- public void onStatusChanged(
- String provider, int status, Bundle extras) {}
- public void onProviderEnabled(String provider) {}
- public void onProviderDisabled(String provider) {}
- };
- locationManager.requestLocationUpdates(
- LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
- // this.addressButton.setOnClickListener(new OnClickListener() {
- // public void onClick(View v){
- progressDialog = ProgressDialog.show(LocationActivity.this,"Please Wait", "Loading Date", true);
- new Thread()
- {
- public void Run()
- {
- try
- {
- getAddress();
- progressDialog.dismiss();
- }
- catch(Exception e)
- {
- }
- }
- }.start();
- }
- void getAddress(){
- StringBuilder result = new StringBuilder();
- try{
- Geocoder gcd = new Geocoder(this, Locale.getDefault());
- List<Address> addresses =
- gcd.getFromLocation(currentLatitude, currentLongitude,100);
- if (addresses.size() > 0)
- {
- Address address = addresses.get(0);
- int maxIndex = address.getMaxAddressLineIndex();
- for (int x = 0; x <= maxIndex; x++ ){
- result.append(address.getAddressLine(x));
- result.append(",");
- }
- }
- //pd.dismiss();
- mHandler.sendEmptyMessage(10);
- addressText.setText(result.toString());
- }
- catch(IOException ex){
- addressText.setText(ex.getMessage().toString());
- }
- }
- void updateLocation(Location location){
- }
- }
Add Comment
Please, Sign In to add comment