Address address = (Address) gotAddresses.get(0); LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude()); String properAddress = String.format("%s, %s", address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "", address.getCountryName()); mMap.addMarker(new MarkerOptions() .position(new LatLng(address.getLatitude(), address.getLongitude())).draggable(true) .title(properAddress) .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin)));
Geocoder geocoder = new Geocoder(context, Locale.getDefault()); Address address = geocoder.getFromLocation(lat, lng, 1); Address obj = addresses.get(0); latLng = new LatLng(obj.getLatitude(), obj.getLongitude()); final String addressText = String.format("%s, %s",obj.getMaxAddressLineIndex() > 0 ? obj.getAddressLine(0) : "", obj.getCountryName());
protected void search(List<Address> addresses) { Address address = (Address) addresses.get(0); home_long = address.getLongitude(); home_lat = address.getLatitude(); latLng = new LatLng(address.getLatitude(), address.getLongitude()); addressText = String.format( "%s, %s", address.getMaxAddressLineIndex() > 0 ? address .getAddressLine(0) : "", address.getCountryName()); markerOptions = new MarkerOptions(); markerOptions.position(latLng); markerOptions.title(addressText); map1.clear(); map1.addMarker(markerOptions); map1.moveCamera(CameraUpdateFactory.newLatLng(latLng)); map1.animateCamera(CameraUpdateFactory.zoomTo(15)); locationTv.setText("Latitude:" + address.getLatitude() + ", Longitude:" + address.getLongitude()); }
public static Address searchLocationByName(Context context, String locationName){ Geocoder geoCoder = new Geocoder(context, Locale.getDefault()); GeoPoint gp = null; Address ad = null; try { List<Address> addresses = geoCoder.getFromLocationName(locationName, 1); for(Address address : addresses){ gp = new GeoPoint((int)(address.getLatitude() * 1E6), (int)(address.getLongitude() * 1E6)); address.getAddressLine(1); ad = address; } } catch (IOException e) { e.printStackTrace(); } return ad; }
Geocoder geocoder = new Geocoder(this); List<Address> addresses = null; try { // Find a maximum of 3 locations with the name Kyoto addresses = geocoder.getFromLocationName("Kyoto", 3); } catch (IOException e) { e.printStackTrace(); } if (addresses != null) { for (Address loc : addresses) { MarkerOptions opts = new MarkerOptions() .position(new LatLng(loc.getLatitude(), loc.getLongitude())) .title(loc.getAddressLine(0)); mMap.addMarker(opts); } }
LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude()); Toast.makeText(getBaseContext(), ""+address.getLatitude()+" - "+address.getLongitude()+"", Toast.LENGTH_SHORT).show();
public String getLatitudeAndLongitudeFromGoogleMapForAddress(String searchedAddress){ Geocoder coder = new Geocoder(this); List<Address> address; try { address = coder.getFromLocationName(searchedAddress,5); if (address == null) { Log.d(TAG, "############Address not correct #########"); } Address location = address.get(0); Log.d(TAG, "Address Latitude : "+ location.getLatitude() + "Address Longitude : "+ location.getLongitude()); for(int i = 0; i<address.size();i++) { Address location2 = address.get(i); Log.d(TAG, "Address : "+ location2.getAddressLine(0)); } return "lat="+ location.getLatitude() +"&long="+ location.getLongitude(); } catch(Exception e) { Log.d(TAG, "MY_ERROR : ############Address Not Found"); return "ERROR"; } }
latLng = new LatLng(address.getLatitude(), address.getLongitude());
latLng = new LatLng(address.getLatitude(), address.getLongitude());
latLng = new LatLng(address.getLatitude(), address.getLongitude());