-4
私は関数place.getLatLng()
を使用していますが、「31°47'0」N 35°13'0「E」として必要です。 これには関数がありますか?Android:LatLngオブジェクトから文字列形式
私は関数place.getLatLng()
を使用していますが、「31°47'0」N 35°13'0「E」として必要です。 これには関数がありますか?Android:LatLngオブジェクトから文字列形式
あなたがロケーションAPIとフォーマットを使用できます。
はLatLangオブジェクトから緯度と経度を取得し、次いでMETHOD-
private String convert(double latitude, double longitude) {
StringBuilder builder = new StringBuilder();
if (latitude < 0) {
builder.append("S ");
} else {
builder.append("N ");
}
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("\"");
builder.append(" ");
if (longitude < 0) {
builder.append("W ");
} else {
builder.append("E ");
}
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("\"");
return builder.toString();
}
を以下に渡し