本文整理汇总了Java中android.location.Location.convert方法的典型用法代码示例。如果您正苦于以下问题:Java Location.convert方法的具体用法?Java Location.convert怎么用?Java Location.convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.convert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMockLocation
import android.location.Location; //导入方法依赖的package包/类
private Location createMockLocation() {
String longitudeString = longitudeInput.getText().toString();
String latitudeString = latitudeInput.getText().toString();
if (!longitudeString.isEmpty() && !latitudeString.isEmpty()) {
double longitude = Location.convert(longitudeString);
double latitude = Location.convert(latitudeString);
Location mockLocation = new Location("flp");
mockLocation.setLatitude(latitude);
mockLocation.setLongitude(longitude);
mockLocation.setAccuracy(1.0f);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
mockLocation.setTime(new Date().getTime());
return mockLocation;
} else {
throw new IllegalArgumentException();
}
}
示例2: convert
import android.location.Location; //导入方法依赖的package包/类
private String convert(double latitude, double longitude) {
StringBuilder builder = new StringBuilder();
String latitudeDegrees = Location.convert(Math.abs(latitude), Location.FORMAT_SECONDS);
String[] latitudeSplit = latitudeDegrees.split(":");
builder.append(latitudeSplit[0]);
builder.append("°");
builder.append(latitudeSplit[1]);
builder.append("'");
builder.append(latitudeSplit[2]);
builder.append("\"");
if (latitude < 0) {
builder.append(" S");
} else {
builder.append(" N");
}
builder.append("\n");
String longitudeDegrees = Location.convert(Math.abs(longitude), Location.FORMAT_SECONDS);
String[] longitudeSplit = longitudeDegrees.split(":");
builder.append(longitudeSplit[0]);
builder.append("°");
builder.append(longitudeSplit[1]);
builder.append("'");
builder.append(longitudeSplit[2]);
builder.append("\"");
if (longitude < 0) {
builder.append(" W");
} else {
builder.append(" E");
}
return builder.toString();
}
示例3: convertLocation
import android.location.Location; //导入方法依赖的package包/类
public static String convertLocation(final Resources res, final double coordinate, final boolean latitude)
{
final String rawStr = Location.convert(coordinate, Location.FORMAT_MINUTES);
//[+-]DDD:MM.MMMMM - FORMAT_MINUTES
final String[] split = rawStr.split(":");
final String direction;
float min = 0f;
//noinspection EmptyCatchBlock
try
{
split[1] = split[1].replace(",",".");
min = Float.parseFloat(split[1]);
}
catch (NumberFormatException e)
{
}
if (latitude)
{
if (coordinate >= 0)
direction = res.getString(R.string.test_location_dir_n);
else
direction = res.getString(R.string.test_location_dir_s);
}
else if (coordinate >= 0)
direction = res.getString(R.string.test_location_dir_e);
else
direction = res.getString(R.string.test_location_dir_w);
return String.format("%s %s°%.3f'", direction, split[0].replace("-", ""), min);
}