本文整理了Java中android.location.Address.getLongitude()
方法的一些代码示例,展示了Address.getLongitude()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getLongitude()
方法的具体详情如下:
包路径:android.location.Address
类名称:Address
方法名:getLongitude
暂无
代码示例来源:origin: stackoverflow.com
public LatLng getLocationFromAddress(Context context,String strAddress) {
Geocoder coder = new Geocoder(context);
List<Address> address;
LatLng p1 = null;
try {
address = coder.getFromLocationName(strAddress, 5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new LatLng(location.getLatitude(), location.getLongitude() );
} catch (Exception ex) {
ex.printStackTrace();
}
return p1;
}
代码示例来源:origin: stackoverflow.com
public GeoPoint getLocationFromAddress(String strAddress){
Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;
try {
address = coder.getFromLocationName(strAddress,5);
if (address==null) {
return null;
}
Address location=address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
(double) (location.getLongitude() * 1E6));
return p1;
}
}
代码示例来源:origin: square/assertj-android
public AddressAssert hasLongitude(double longitude) {
isNotNull();
double actualLongitude = actual.getLongitude();
assertThat(actualLongitude) //
.overridingErrorMessage("Expected longitude <%s> but was <%s>.", longitude,
actualLongitude) //
.isEqualTo(longitude);
return this;
}
代码示例来源:origin: stackoverflow.com
try {
List<Address> geoResults = geocoder.getFromLocationName("<address goes here>", 1);
while (geoResults.size()==0) {
geoResults = geocoder.getFromLocationName("<address goes here>", 1);
}
if (geoResults.size()>0) {
Address addr = geoResults.get(0);
myLocation.setLatitude(addr.getLatitude());
myLocation.setLongitude(addr.getLongitude());
}
} catch (Exception e) {
System.out.print(e.getMessage());
}
代码示例来源:origin: stackoverflow.com
final Geocoder geocoder = new Geocoder(this);
final String zip = "90210";
try {
List<Address> addresses = geocoder.getFromLocationName(zipCode, 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
// Use the address as needed
String message = String.format("Latitude: %f, Longitude: %f",
address.getLatitude(), address.getLongitude());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
} else {
// Display appropriate message when Geocoder services are not available
Toast.makeToast(this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// handle exception
}
代码示例来源:origin: stackoverflow.com
if(Geocoder.isPresent()){
try {
String location = "theNameOfTheLocation";
Geocoder gc = new Geocoder(this);
List<Address> addresses= gc.getFromLocationName(location, 5); // get the found Address Objects
List<LatLng> ll = new ArrayList<LatLng>(addresses.size()); // A list to save the coordinates if they are available
for(Address a : addresses){
if(a.hasLatitude() && a.hasLongitude()){
ll.add(new LatLng(a.getLatitude(), a.getLongitude()));
}
}
} catch (IOException e) {
// handle the exception
}
}
代码示例来源:origin: stackoverflow.com
if (addressList == null)
{
Log.d(TAG,"Latitude and longitude not found");
}
else {
Address location = addressList.get(0);
latitude = location.getLatitude();
longitude = location.getLongitude();
}
代码示例来源:origin: stackoverflow.com
Geocoder coder = new Geocoder(LocationMap.this);
List<Address> geocodeResults = coder.getFromLocationName(placeName, 10);
Iterator<Address> locations = geocodeResults.iterator();
while (locations.hasNext()) {
Address loc = locations.next();
_lattitude_ = loc.getLatitude() ;
_longidude_ = loc.getLongitude();
}
代码示例来源:origin: stackoverflow.com
address = coder.getFromLocationName(strAddress, 5);
if (address != null && address.size() > 0) {
Address location = address.get(0);
p1 = new LatLng(location.getLatitude(), location.getLongitude());
} else {
p1 = new LatLng(19.111258, 72.908313);
}
代码示例来源:origin: stackoverflow.com
address = coder.getFromLocationName(strAddress, 5);
if (address != null) {
Address location = address.get(0);
p1 = new LatLng(location.getLatitude(), location.getLongitude());
} else {
p1 = new LatLng(19.111258, 72.908313);
}
代码示例来源:origin: stackoverflow.com
Geocoder geocoder = new Geocoder(getBaseContext());
List<Address> addresses;
try {
addresses = geocoder.getFromLocationName("Example StreeT, UK, DNFE", 20);
for(int i = 0; i < addresses.size(); i++) { // MULTIPLE MATCHES
Address addr = addresses.get(i);
double latitude = addr.getLatitude();
double longitude = addr.getLongitude(); // DO SOMETHING WITH VALUES
}
}
代码示例来源:origin: stackoverflow.com
Geocoder geo = new Geocoder(this);
List<Address> addr;
try
{
addr = coder.getFromLocationName(yourEditTextaddr, 10);
Address loc = addr.get(0);
loc.getLatitude();
loc.getLongitude();
point = new GeoPoint((int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
return point;
}
代码示例来源:origin: stackoverflow.com
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
String textToSearch = searchText.getText().toString();
List<Address> fromLocationName = null;
fromLocationName = geocoder.getFromLocationName(texToSearch, 1);
if (fromLocationName != null && fromLocationName.size() > 0) {
Address a = fromLocationName.get(0);
GeoPoint point = new GeoPoint(
(int) (a.getLatitude() * _1E6),
(int) (a.getLongitude() * _1E6));
}
代码示例来源:origin: stackoverflow.com
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocationName(myLocation, 1);
Address address = addresses.get(0);
double longitude = address.getLongitude();
double latitude = address.getLatitude();
代码示例来源:origin: stackoverflow.com
Geocoder coder = new Geocoder(this);
try {
ArrayList<Address> adresses = (ArrayList<Address>) coder.getFromLocationName("Your Address", 50);
for(Address add : adresses){
if (statement) {//Controls to ensure it is right address such as country etc.
double longitude = add.getLongitude();
double latitude = add.getLatitude();
}
}
} catch (IOException e) {
e.printStackTrace();
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public AddressAssert hasLongitude(double longitude) {
isNotNull();
double actualLongitude = actual.getLongitude();
assertThat(actualLongitude) //
.overridingErrorMessage("Expected longitude <%s> but was <%s>.", longitude,
actualLongitude) //
.isEqualTo(longitude);
return this;
}
代码示例来源:origin: stackoverflow.com
List<Address> addressList = geoCoder.getFromLocationName(cityName, 1);
Address address = addressList.get(0);
if(address.hasLatitude() && address.hasLongitude()){
double selectedLat = address.getLatitude();
double selectedLng = address.getLongitude();
}
代码示例来源:origin: stackoverflow.com
Geocoder coder = new Geocoder(this);
List<Address> address;
try {
address = coder.getFromLocationName(strAddress,5);
if (address == null) {
return null;
}
Address location = address.get(0);
lat = location.getLatitude(); // get lat
lng = location.getLongitude(); // get lng
return p1;
}
代码示例来源:origin: stackoverflow.com
Geocoder coder = new Geocoder(this);
List<Address> address = coder.getFromLocationName(
"your address", 5);
if (address == null)
Log.d(TAG,
"Latitude and longitude not found");
else {
Address location = address.get(0);
latitude = location.getLatitude();
longitude = location.getLongitude();
}
代码示例来源:origin: j4velin/MapsMeasure
@Override
protected void onPostExecute(final Address address) {
if (address == null) {
if (BuildConfig.DEBUG) Logger.log("no location found");
Toast.makeText(map.getBaseContext(), R.string.no_location_found, Toast.LENGTH_SHORT).show();
} else {
map.getMap().animateCamera(CameraUpdateFactory
.newLatLngZoom(new LatLng(address.getLatitude(), address.getLongitude()),
Math.max(10, map.getMap().getCameraPosition().zoom)));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!