List of usage examples for android.location Geocoder getFromLocation
public List<Address> getFromLocation(double latitude, double longitude, int maxResults) throws IOException
From source file:com.cmput301w17t07.moody.EditMoodActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); UserController userController = new UserController(); userName = userController.readUsername(EditMoodActivity.this).toString(); setContentView(R.layout.activity_edit_mood); setUpMenuBar(this); // get the mood object that was selected Intent intent = getIntent();/*from ww w . j av a 2 s . c o m*/ editMood = (Mood) intent.getSerializableExtra("editMood"); date = editMood.getDate(); bitmapImage = (Bitmap) intent.getParcelableExtra("bitmapback"); editBitmapImage = bitmapImage; deletedPic = (int) intent.getExtras().getInt("bitmapdelete"); latitude = editMood.getLatitude(); longitude = editMood.getLongitude(); image = (ImageView) findViewById(R.id.editImageView); final TextView location = (TextView) findViewById(R.id.locationText); address = editMood.getDisplayLocation(); location.setText(address); if (latitude == 0 && longitude == 0) { location1 = null; } displayAttributes(); if (deletedPic == 1) { image.setImageBitmap(null); } //set up the button and imageButton ImageButton editLocation = (ImageButton) findViewById(R.id.location); editLocation.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { locationText = (TextView) findViewById(R.id.locationText); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //check available tools List<String> locationList = locationManager.getProviders(true); if (locationList.contains(LocationManager.GPS_PROVIDER)) { provider = LocationManager.GPS_PROVIDER; } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) { provider = LocationManager.NETWORK_PROVIDER; } else { Toast.makeText(getApplicationContext(), "Please check your permissions", Toast.LENGTH_LONG) .show(); } //check the permission if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling Toast.makeText(getApplicationContext(), "Getting location failed, Please check the application permissions", Toast.LENGTH_SHORT) .show(); return; } location1 = locationManager.getLastKnownLocation(provider); if (location1 == null) { latitude = 0; longitude = 0; } else { latitude = location1.getLatitude(); longitude = location1.getLongitude(); } //get the location name by latitude and longitude Geocoder gcd = new Geocoder(EditMoodActivity.this, Locale.getDefault()); try { List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) address = " " + addresses.get(0).getFeatureName() + " " + addresses.get(0).getThoroughfare() + ", " + addresses.get(0).getLocality() + ", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode(); location.setText(address); } catch (Exception e) { e.printStackTrace(); } final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation); deleteLocation.setVisibility(View.VISIBLE); deleteLocation.setEnabled(true); } }); editLocation.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View view) { moodMessage_text = Description.getText().toString(); editMood.setMoodMessage(moodMessage_text); editMood.setDate(date); Intent editLocation = new Intent(EditMoodActivity.this, EditLocation.class); editLocation.putExtra("EditMood", editMood); editLocation.putExtra("bitmap", compress(editBitmapImage)); startActivity(editLocation); return true; } }); final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation); deleteLocation.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { location1 = null; locationText = (TextView) findViewById(R.id.locationText); address = null; locationText.setText(address); latitude = 0; longitude = 0; deleteLocation.setVisibility(View.INVISIBLE); deleteLocation.setEnabled(false); } }); ImageButton editCameraButton = (ImageButton) findViewById(R.id.editCamera); editCameraButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, 1); } catch (Exception e) { Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class); startActivity(intent); } } }); editCameraButton.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View view) { try { Intent intent = new Intent("android.intent.action.PICK"); intent.setType("image/*"); startActivityForResult(intent, 0); } catch (Exception e) { Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class); startActivity(intent); } return true; } }); ImageButton PickerButton = (ImageButton) findViewById(R.id.EditDate); PickerButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { innit(); TimeDialog.show(); } }); Button submitButton = (Button) findViewById(R.id.button5); submitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { moodMessage_text = Description.getText().toString(); MoodController moodController = new MoodController(); editBitmapImage = bitmapImage; AchievementManager.initManager(EditMoodActivity.this); AchievementController achievementController = new AchievementController(); achievements = achievementController.getAchievements(); achievements.firstTimeEditFlag = 1; achievementController.saveAchievements(); if (!moodController.editMood(EmotionText, userName, moodMessage_text, latitude, longitude, editBitmapImage, SocialSituation, date, address, editMood, EditMoodActivity.this)) { Toast.makeText(EditMoodActivity.this, "Mood message length is too long. Please try again", Toast.LENGTH_SHORT).show(); } else { Intent intent = new Intent(EditMoodActivity.this, TimelineActivity.class); startActivity(intent); finish(); } } }); // TODO button needs only display when image present in Mood final ImageButton deletePicture = (ImageButton) findViewById(R.id.deletePicture); if (editBitmapImage == null || deletedPic == 1) { deletePicture.setVisibility(View.INVISIBLE); deletePicture.setEnabled(false); } deletePicture.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { bitmapImage = null; editBitmapImage = null; image.setImageDrawable(null); deletePicture.setVisibility(View.INVISIBLE); deletePicture.setEnabled(false); } }); }
From source file:com.tingbacke.wearmaps.MobileActivity.java
/** * Updates my location to currentLocation, moves the camera. * * @param location/*from w w w. ja v a2 s .co m*/ */ private void handleNewLocation(Location location) { Log.d(TAG, location.toString()); double latitude = location.getLatitude(); double longitude = location.getLongitude(); LatLng latLng = new LatLng(latitude, longitude); mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(18).bearing(0).tilt(25) .build(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); TextView myLatitude = (TextView) findViewById(R.id.textView); TextView myLongitude = (TextView) findViewById(R.id.textView2); TextView myAddress = (TextView) findViewById(R.id.textView3); ImageView myImage = (ImageView) findViewById(R.id.imageView); myLatitude.setText("Latitude: " + String.valueOf(latitude)); myLongitude.setText("Longitude: " + String.valueOf(longitude)); // Instantiating currDistance to get distance to destination from my location currDistance = getDistance(latitude, longitude, destLat, destLong); Geocoder geocoder = new Geocoder(this, Locale.ENGLISH); try { List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses != null) { Address returnedAddress = addresses.get(0); StringBuilder strReturnedAddress = new StringBuilder(""); for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) { strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n"); } // Hardcoded string which searches through strReturnedAddress for specifics // if statements decide which information will be displayed String fake = strReturnedAddress.toString(); if (fake.contains("stra Varvsgatan")) { myAddress.setText("K3, Malm Hgskola" + "\n" + "Cykelparkering: 50m" + "\n" + "Dest: " + Math.round(currDistance) + "m away"); myImage.setImageResource(R.mipmap.kranen); } else if (fake.contains("Lilla Varvsgatan")) { myAddress.setText("Turning Torso" + "\n" + "Caf: 90m " + "\n" + "Dest: " + Math.round(currDistance) + "m away"); myImage.setImageResource(R.mipmap.turning); } else if (fake.contains("Vstra Varvsgatan")) { myAddress.setText("Kockum Fritid" + "\n" + "Bankomat: 47m" + "\n" + "Dest: " + Math.round(currDistance) + "m away"); myImage.setImageResource(R.mipmap.kockum); } else if (fake.contains("Stapelbddsgatan")) { myAddress.setText("Stapelbddsparken" + "\n" + "Toalett: 63m" + "\n" + "Dest: " + Math.round(currDistance) + "m away"); myImage.setImageResource(R.mipmap.stapel); } else if (fake.contains("Stora Varvsgatan")) { myAddress.setText("Media Evolution City" + "\n" + "Busshllplats: 94m" + "\n" + "Dest: " + Math.round(currDistance) + "m away"); myImage.setImageResource(R.mipmap.media); } else if (fake.contains("Masttorget")) { myAddress.setText("Ica Maxi" + "\n" + "Systembolaget: 87m" + "\n" + "Dest: " + Math.round(currDistance) + "m away"); myImage.setImageResource(R.mipmap.ica); } else if (fake.contains("Riggaregatan")) { myAddress.setText("Scaniabadet" + "\n" + "\n" + "Dest: " + Math.round(currDistance) + "m away"); myImage.setImageResource(R.mipmap.scaniabadet); } else if (fake.contains("Dammfrivgen")) { //fakear Turning Torso p min adress fr tillfllet myAddress.setText("Turning Torso" + "\n" + "453m away"); myImage.setImageResource(R.mipmap.turning); } //myAddress.setText(strReturnedAddress.toString()+ "Dest: " + Math.round(currDistance) + "m away"); /* // Added this Toast to display address ---> In order to find out where to call notification builder for wearable Toast.makeText(MobileActivity.this, myAddress.getText().toString(), Toast.LENGTH_LONG).show(); */ //Here is where I call the notification builder for the wearable showNotification(1, "basic", getBasicNotification("myStack")); } else { myAddress.setText("No Address returned!"); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); myAddress.setText("Cannot get Address!"); } }
From source file:com.jbsoft.farmtotable.FarmToTableActivity.java
private void getZipFromLocation(final Location location, final Context context) { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); try {// ww w . j a va2s . c o m List<Address> list = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); if (list != null && list.size() > 0) { Address address = list.get(0); // sending back first address line and locality zipcode = address.getPostalCode(); } } catch (IOException e) { Log.e(TAG, "Impossible to connect to Geocoder", e); } finally { } }
From source file:de.sindzinski.wetter.MainActivity.java
public String getLocationSetting(double lat, double lon) { String locationSetting = ""; //locale must be set to us for getting english countey names Geocoder geoCoder = new Geocoder(this, Locale.US); StringBuilder builder = new StringBuilder(); try {/* w w w . ja v a 2 s . c o m*/ List<Address> address = geoCoder.getFromLocation(lat, lon, 1); // String countryCode = address.get(0).getCountryCode(); String country = address.get(0).getCountryName(); // String country = CountryCodes.getCountry(countryCode); String locality = address.get(0).getLocality(); // String adminArea = address.get(0).getAdminArea(); builder.append(country).append("/") // .append(adminArea); .append(locality); locationSetting = builder.toString(); //This is the complete locationsetting as wug. locationSetting = wordFirstCap(locationSetting, "/"); } catch (IOException e) { } catch (NullPointerException e) { } return locationSetting; }
From source file:com.TakeTaxi.jy.MainMapScreen.java
public void setGeoText() { geoadd = null;/*from w w w. ja va 2 s. c om*/ Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault()); try { List<Address> address = geocoder.getFromLocation(newLat / 1E6, newLongi / 1E6, 1); if (address.size() > 0) { geoadd = ""; for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++) { if (i == 0) { geoadd += address.get(0).getAddressLine(i); } else { geoadd += "\n" + address.get(0).getAddressLine(i); } } } } catch (IOException e) { e.printStackTrace(); } finally { } tvCurrentGeocode = (TextView) findViewById(R.id.tvCurrentGeocode); tvCurrentGeocode.setText(geoadd); }
From source file:com.cmput301w17t07.moody.CreateMoodActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_mood); UserController userController = new UserController(); userName = userController.readUsername(CreateMoodActivity.this).toString(); setUpMenuBar(this); location = null;/*from www .j a va 2 s . c o m*/ date = new Date(); Intent intent = getIntent(); locationText = (TextView) findViewById(R.id.locationText); Description = (EditText) findViewById(R.id.Description); mImageView = (ImageView) findViewById(R.id.editImageView); //try to get picklocation, if it is equal to 1 that means, user just back from map not //other activities try { pickLocation = (int) intent.getExtras().getInt("pickLocation"); } catch (Exception e) { e.printStackTrace(); } if (pickLocation == 1) { tempMood = (Mood) intent.getSerializableExtra("editMood"); bitmap = (Bitmap) intent.getParcelableExtra("bitmapback"); latitude = tempMood.getLatitude(); longitude = tempMood.getLongitude(); address = tempMood.getDisplayLocation(); locationText.setText(address); Description.setText(tempMood.getMoodMessage()); mImageView.setImageBitmap(bitmap); date = tempMood.getDate(); displayAttributes(); } /** * Spinner dropdown logic taken from http://stackoverflow.com/questions/13377361/how-to-create-a-drop-down-list <br> * Author: Nicolas Tyler, 2013/07/15 8:47 <br> * taken by Xin Huang 2017/03/10 <br> */ //Spinner for emotion and socialsituatuion if (pickLocation == 0) { Spinner dropdown = (Spinner) findViewById(R.id.Emotion); String[] items = new String[] { "anger", "confusion", "disgust", "fear", "happiness", "sadness", "shame", "surprise" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items); dropdown.setAdapter(adapter); dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { EmotionText = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(CreateMoodActivity.this, "Please pick a feeling!", Toast.LENGTH_SHORT).show(); } }); Spinner dropdown_SocialSituation = (Spinner) findViewById(R.id.SocialSituation); String[] item_SocialSituation = new String[] { "", "alone", "with one other person", "with two people", "with several people", "with a crowd" }; ArrayAdapter<String> adapter_SocialSituation = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, item_SocialSituation); dropdown_SocialSituation.setAdapter(adapter_SocialSituation); dropdown_SocialSituation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SocialSituation = parent.getItemAtPosition(position).toString(); TextView sizeView = (TextView) findViewById(R.id.SocialText); sizeView.setText(" " + SocialSituation); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } ImageButton chooseButton = (ImageButton) findViewById(R.id.Camera); ImageButton locationButton = (ImageButton) findViewById(R.id.location); ImageButton PickerButton = (ImageButton) findViewById(R.id.Picker); //click on PickerButton, call the datetimePicker PickerButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { innit(); TimeDialog.show(); } }); chooseButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, 1); } catch (Exception e) { Intent intent = new Intent(getApplicationContext(), CreateMoodActivity.class); startActivity(intent); } } }); chooseButton.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View view) { try { Intent intent = new Intent("android.intent.action.PICK"); intent.setType("image/*"); startActivityForResult(intent, 0); } catch (Exception e) { Intent intent = new Intent(getApplicationContext(), CreateMoodActivity.class); startActivity(intent); } return true; } }); locationButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //check available tools List<String> locationList = locationManager.getProviders(true); if (locationList.contains(LocationManager.GPS_PROVIDER)) { provider = LocationManager.GPS_PROVIDER; } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) { provider = LocationManager.NETWORK_PROVIDER; } else { Toast.makeText(getApplicationContext(), "Please check application permissions", Toast.LENGTH_LONG).show(); } //check the permission if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling Toast.makeText(getApplicationContext(), "Get location failed, Please check the Permission", Toast.LENGTH_SHORT).show(); return; } location = locationManager.getLastKnownLocation(provider); if (location == null) { latitude = 0; longitude = 0; } else { latitude = location.getLatitude(); longitude = location.getLongitude(); } Geocoder gcd = new Geocoder(CreateMoodActivity.this, Locale.getDefault()); try { List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) address = " " + addresses.get(0).getFeatureName() + " " + addresses.get(0).getThoroughfare() + ", " + addresses.get(0).getLocality() + ", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode(); locationText.setText(address); } catch (Exception e) { e.printStackTrace(); } } }); //pass users' changes to map, will be passed back locationButton.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View view) { int fromCreate = 123; moodMessage_text = Description.getText().toString(); tempMood = new Mood(EmotionText, userName, moodMessage_text, latitude, longitude, null, SocialSituation, date, address); Intent editLocation = new Intent(CreateMoodActivity.this, EditLocation.class); editLocation.putExtra("EditMood", tempMood); editLocation.putExtra("fromCreate", fromCreate); editLocation.putExtra("bitmap", compress(bitmap)); startActivity(editLocation); return true; } }); Button submitButton = (Button) findViewById(R.id.button5); submitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { moodMessage_text = Description.getText().toString(); MoodController moodController = new MoodController(); // --------------------------- achievements ------------------------------------- AchievementManager.initManager(CreateMoodActivity.this); AchievementController achievementController = new AchievementController(); achievements = achievementController.getAchievements(); achievements.moodCount += 1; achievementController.incrementMoodCounter(EmotionText); achievementController.saveAchievements(); // ------------------------------------------------------------------------------ if (location != null || pickLocation == 1) { //todo can remove these if/else statements that toast message too long. They could // be handled in the controller if (!MoodController.createMood(EmotionText, userName, moodMessage_text, latitude, longitude, bitmap, SocialSituation, date, address, CreateMoodActivity.this)) { Toast.makeText(CreateMoodActivity.this, "Mood message length is too long. Please try again.", Toast.LENGTH_SHORT).show(); } else { Intent intent = new Intent(CreateMoodActivity.this, TimelineActivity.class); startActivity(intent); finish(); } } else { if (!MoodController.createMood(EmotionText, userName, moodMessage_text, 0, 0, bitmap, SocialSituation, date, address, CreateMoodActivity.this)) { Toast.makeText(CreateMoodActivity.this, "Mood message length is too long. Please try again.", Toast.LENGTH_SHORT).show(); } else { Intent intent = new Intent(CreateMoodActivity.this, TimelineActivity.class); startActivity(intent); finish(); } } } }); }
From source file:com.israel_fl.smartadaptweather.activities.MainActivity.java
@Override public void onConnected(@Nullable Bundle bundle) { Log.d(TAG, "onConnected called"); try {//from w ww . j a va 2 s . co m mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); } catch (SecurityException e) { e.printStackTrace(); } Log.d(TAG, "Last Location: " + mLastLocation); latitude = mLastLocation.getLatitude(); longitude = mLastLocation.getLongitude(); Log.d(TAG, "Latitude: " + latitude + " Longitude: " + longitude); // Set title bar name to name of city Geocoder gcd = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) { cityName = addresses.get(0).getLocality(); } } catch (IOException e) { e.printStackTrace(); } // Set title to city name if (getSupportActionBar() != null) { getSupportActionBar().setTitle(cityName); } getWeatherInfo(); // begin weather api modifyConfig(); // modify weather settings Log.d(TAG, "Last Location: " + mLastLocation); }
From source file:com.cecs492a_group4.sp.SingleEvent.java
public String reverseGeocode(double latitude, double longitude) throws IOException { Geocoder gc = new Geocoder(this); if (gc.isPresent()) { List<Address> list = gc.getFromLocation(latitude, longitude, 1); //(latitude, longitude, 1) //33.777043, -118.114395, 1) Address address = list.get(0);//from w w w. j av a 2 s . c o m StringBuffer str = new StringBuffer(); if (address.getAddressLine(0) != null && address.getLocality() != null && address.getAdminArea() != null && address.getPostalCode() != null && address.getCountryName() != null) { //str.append(address.getAddressLine(0) + ", "); //str.append(address.getLocality() + ", "); //str.append(address.getAdminArea() + " "); //str.append(address.getPostalCode() + ", "); //str.append(address.getCountryName()); //str.append("USA"); //String strAddress = str.toString(); String strAddress = (address.getAddressLine(0) + ", " + address.getLocality() + ", " + address.getAdminArea() + " " + address.getPostalCode() + ", " + "USA"); return strAddress; } else { return null; } } return null; }
From source file:com.mainpanel.LifeApp_Map.java
/** * Button to get current Location. This demonstrates how to get the current Location as required * without needing to register a LocationListener. * @throws IOException /*w w w.ja v a 2 s .c o m*/ */ public void showMyLocation(View view) throws IOException { String location_name = "unknown"; if (mLocationClient != null && mLocationClient.isConnected()) { onMyLocationButtonClick(); String msg = ""; my_lat = mLocationClient.getLastLocation().getLatitude(); my_longi = mLocationClient.getLastLocation().getLongitude(); // my_lat = 40.6944; // my_longi = -73.9865; //get address from Latitude and Longitude Geocoder gcd = new Geocoder(this, Locale.getDefault()); List<Address> addresses = gcd.getFromLocation(my_lat, my_longi, 100); if (addresses.size() > 0 && addresses != null) { msg = "Address : " + addresses.get(0).getFeatureName() + "-" + addresses.get(0).getLocality() + "-" + addresses.get(0).getAdminArea() + "-" + addresses.get(0).getCountryName(); location_name = addresses.get(0).getFeatureName() + "-" + addresses.get(0).getLocality() + "-" + addresses.get(0).getAdminArea() + "-" + addresses.get(0).getCountryName(); } msg += "\nLatitude : " + my_lat; msg += "\nLongitude : " + my_longi; Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); } Log.d("mymap", "In showMyLocation"); }
From source file:com.RSMSA.policeApp.OffenceReportForm.java
public String getAddress(double lat, double lng) { Geocoder geocoder = new Geocoder(OffenceReportForm.this, Locale.getDefault()); String address = ""; try {/*from w w w . j a v a 2 s . c om*/ List<Address> addresses = geocoder.getFromLocation(lat, lng, 1); Address obj = addresses.get(0); String add = ""; if (obj.getAdminArea() != null) { add = add + obj.getAdminArea(); } if (obj.getSubAdminArea() != null) { add = add + ", " + obj.getSubAdminArea(); } if (obj.getAddressLine(0) != null) { add = add + ", " + obj.getAddressLine(0); } address = add; Log.v("IGA", "Address" + add); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { } return address; }