初めまして
現在私が使用しているものです
import java.util.List;
import com.google.code.geocoder.Geocoder;
import com.google.code.geocoder.GeocoderRequestBuilder;
import com.google.code.geocoder.model.GeocodeResponse;
import com.google.code.geocoder.model.GeocoderGeometry;
import com.google.code.geocoder.model.GeocoderRequest;
import com.google.code.geocoder.model.GeocoderResult;
import com.google.code.geocoder.model.GeocoderStatus;
import com.google.code.geocoder.model.LatLng;
public class GoogleGeocoder {
// public static void main(String[] args) {
// LatLng latlng = geocode("皇居");
// System.out.println(latlng.getLat() + "/" + latlng.getLng());
// }
public static LatLng geocode(String address) {
final Geocoder geocoder = new Geocoder();
GeocoderRequest req = new GeocoderRequestBuilder().setAddress(address)
.setLanguage("ja").getGeocoderRequest();
GeocodeResponse res = null;
try {
res = geocoder.geocode(req);
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
GeocoderStatus status = res.getStatus();
switch (status) {
case ZERO_RESULTS:
return null;
case OVER_QUERY_LIMIT:
case REQUEST_DENIED:
case INVALID_REQUEST:
case UNKNOWN_ERROR:
case ERROR:
throw new RuntimeException(status.value());
default:
}
List<GeocoderResult> results = res.getResults();
for (GeocoderResult result : results) {
GeocoderGeometry geometry = result.getGeometry();
return geometry.getLocation();
}
return null;
}
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/09/16 04:17
退会済みユーザー
2015/09/16 04:30
2015/09/16 04:41
退会済みユーザー
2015/09/16 05:07
2015/09/16 05:09
退会済みユーザー
2015/09/16 05:44
2015/09/16 11:12
退会済みユーザー
2015/09/17 00:57