Java Code Examples for android.location.Address#getLongitude()
The following examples show how to use
android.location.Address#getLongitude() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From Android-Example with Apache License 2.0 | 6 votes |
public String getAddress(Context ctx, double latitude, double longitude) { StringBuilder result = new StringBuilder(); try { Geocoder geocoder = new Geocoder(ctx, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) { Address address = addresses.get(0); String locality=address.getLocality(); String city=address.getCountryName(); String region_code=address.getCountryCode(); String zipcode=address.getPostalCode(); double lat =address.getLatitude(); double lon= address.getLongitude(); result.append(locality+" "); result.append(city+" "+ region_code+" "); result.append(zipcode); } } catch (IOException e) { Log.e("tag", e.getMessage()); } return result.toString(); }
Example 2
Source File: LoadMapActivity.java From Stayfit with Apache License 2.0 | 6 votes |
protected void sendSMSMessage() { Log.i("Send SMS", ""); String phoneNo = phoneno; //String lat = getIntent().getExtras().getString("Latitude"); //String lng = getIntent().getExtras().getString("Longitude"); // Replace latitude and longitude values Address msgaddress = AskLocationActivity.address1; String message = "Shall we run together, Location:" + "http://maps.google.com/?q=" + msgaddress.getLatitude() + "," + msgaddress.getLongitude(); Log.d("Message", message); try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNo, null, message, null, null); Toast.makeText(getApplicationContext(), "Invitation sent.", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show(); e.printStackTrace(); } }
Example 3
Source File: Venue.java From mConference-Framework with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected Void doInBackground(Void... params) { latitude = Double.longBitsToDouble(sharedPref.getLong(LAT, 0)); longitude = Double.longBitsToDouble(sharedPref.getLong(LONG, 0)); Address returnedAddress; if (latitude == 0 && longitude == 0 || SECOND_APPROACH) { returnedAddress = getAddressFromLocation(getContext(), venueAddress); SharedPreferences.Editor editor = sharedPref.edit(); if (returnedAddress != null) { editor.putLong(LAT, Double.doubleToLongBits(returnedAddress.getLatitude())); editor.putLong(LONG, Double.doubleToLongBits(returnedAddress.getLongitude())); editor.apply(); latitude = returnedAddress.getLatitude(); longitude = returnedAddress.getLongitude(); } } return null; }
Example 4
Source File: LocationHelper.java From SampleApp with Apache License 2.0 | 6 votes |
/** * to get latitude and longitude of an address * * @param strAddress address string * @return lat and lng in comma separated string */ public String getLocationFromAddress(String strAddress) { Geocoder coder = new Geocoder(mContext); List<Address> address; try { address = coder.getFromLocationName(strAddress, 1); if (address == null) { return null; } Address location = address.get(0); double lat = location.getLatitude(); double lng = location.getLongitude(); return lat + "," + lng; } catch (Exception e) { return null; } }
Example 5
Source File: MapActions.java From PocketMaps with MIT License | 6 votes |
private OnClickAddressListener createPosSelectedListener(final boolean isStartP) { OnClickAddressListener callbackListener = new OnClickAddressListener() { @Override public void onClick(Address addr) { GeoPoint newPos = new GeoPoint(addr.getLatitude(), addr.getLongitude()); String fullAddress = ""; for (int i=0; i<5; i++) { String curAddr = addr.getAddressLine(i); if (curAddr == null || curAddr.isEmpty()) { continue; } if (!fullAddress.isEmpty()) { fullAddress = fullAddress + ", "; } fullAddress = fullAddress + curAddr; } doSelectCurrentPos(newPos, fullAddress, isStartP); } }; return callbackListener; }
Example 6
Source File: OmniArea.java From LibreTasks with Apache License 2.0 | 5 votes |
/** * Creates OmniArea object for a given address. * * @param context * application context. Must not be null. * @param address * address of the location to be identified (a.k.a 1600 Amphitheatre Parkway, Mountain * View, CA 94043). * @return OmniArea object for a given address. * @throws IOException * if Internet access is unavailable. * @throws IllegalArgumentException * if either context or address are null, or address cannot be found. */ public static OmniArea getOmniArea(Context context, String address, double proximityDistance) throws IOException, IllegalArgumentException { final int MAX_RESULTS_TO_RETURN = 1; final int FIRST_RESULT = 0; if (context == null) { throw new IllegalArgumentException("context cannot be null."); } if (address == null) { throw new IllegalArgumentException("address cannot be null."); } Geocoder geocoder = new Geocoder(context, Locale.getDefault()); List<Address> addressResult = geocoder.getFromLocationName(address, MAX_RESULTS_TO_RETURN); if (!addressResult.isEmpty()) { Address location = addressResult.get(FIRST_RESULT); try { return new OmniArea(address, location.getLongitude(), location.getLatitude(), proximityDistance); } catch (DataTypeValidationException e) { throw new IllegalArgumentException("address cannot be found."); } } throw new IllegalArgumentException("address cannot be found."); }
Example 7
Source File: VPNFragment.java From android with GNU General Public License v3.0 | 4 votes |
@Override public void success(final IPService.Data data, Response response) { if(mActivity == null) return; if(response != null && response.getStatus() == 200) { mShowsConnected = data.connected; mDetectedCountry = data.country; if(!mShowsConnected && mCurrentVPNState.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED)) { updateIPData(); return; } String location = null; if (mShowsConnected) { mConnectedCard.setVisibility(View.VISIBLE); } else { mConnectedCard.setVisibility(View.GONE); try { Geocoder coder = new Geocoder(mActivity); List<Address> addressList; if (!data.hasCoordinates()) { addressList = coder.getFromLocationName("Country: " + data.country, 1); } else { addressList = coder.getFromLocation(data.getLat(), data.getLng(), 1); } if (addressList != null && addressList.size() > 0) { Address address = addressList.get(0); if (address.getLocality() == null) { location = address.getCountryName(); } else { location = String.format("%s, %s", address.getLocality(), address.getCountryCode()); } if (address.hasLatitude() && address.hasLongitude()) mCurrentLocation = new LatLng(address.getLatitude(), address.getLongitude()); } } catch (IOException e) { e.printStackTrace(); } } if (location == null && data.country != null) { Locale locale = new Locale("", data.country); location = locale.getDisplayCountry(); } final String finalLocation = location; ThreadUtils.runOnUiThread(new Runnable() { @Override public void run() { mIPText.setText(data.ip); mLocationText.setText(finalLocation); } }); processServers(); updateMapLocation(); } }