本文整理汇总了Java中com.google.code.geocoder.model.LatLng类的典型用法代码示例。如果您正苦于以下问题:Java LatLng类的具体用法?Java LatLng怎么用?Java LatLng使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LatLng类属于com.google.code.geocoder.model包,在下文中一共展示了LatLng类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: calculateCoordinateForAddress
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
/**
* calls the google geocode api and enrich the given address with latitude
* and longitude information
*
* It expects a valid german address. There is not check if the address is correct.
*
* @param address
* @return
*/
public static Coordinate calculateCoordinateForAddress(Address address) {
String requestAddress = "";
requestAddress += address.getStreet() != null ? address.getStreet() + " " : "";
requestAddress += (address.getStreet() != null && address.getStreetNumber() != null) ? address.getStreetNumber() + " " : "";
requestAddress += address.getZipCode() != null ? address.getZipCode() + " " : "";
requestAddress += address.getCity()!= null ? address.getCity() + " " : "";
requestAddress += ", Deutschland";
try {
final Geocoder geocoder = new Geocoder();
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(requestAddress).setLanguage("de").getGeocoderRequest();
List<GeocoderResult> geocoderResults = geocoder.geocode(geocoderRequest).getResults();
if (geocoderResults.isEmpty()) {
throw new RuntimeException("Google geocode could not find any results for: " + requestAddress); //TODO for testing purposes an exception is fine, how about in production?
}
//use first result, hopefully it is the best
LatLng location = geocoderResults.get(0).getGeometry().getLocation();
return new Coordinate(location.getLat().doubleValue(), location.getLng().doubleValue());
} catch (IOException e) {
throw new RuntimeException("Could not gather google geocode api for parameter: " + requestAddress); //TODO for testing purposes an exception is fine, how about in production?
}
}
开发者ID:HelfenKannJeder,项目名称:come2help,代码行数:33,代码来源:GeoCodeCaller.java
示例2: testAccurateSearch
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
@Test
public void testAccurateSearch() throws IOException {
//My Home :-)
String myHome = "237 Avenue Jean Jaurès 69007 Lyon France";
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(myHome)
.setRegion("fr").setLanguage("fr").getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
assertFalse(geocoderResponse.getResults().isEmpty());
GeocoderResult geocoderResult = geocoderResponse.getResults().iterator().next();
LatLng location = geocoderResult.getGeometry().getLocation();
geocoderRequest = new GeocoderRequestBuilder().setLocation(location).setLanguage("fr").getGeocoderRequest();
geocoderResponse = geocoder.geocode(geocoderRequest);
assertTrue(geocoderResult.getFormattedAddress().contains(myHome));
}
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:18,代码来源:TestGeocoder.java
示例3: testBoundingCity
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
@Test
public void testBoundingCity() throws IOException {
LatLng limit_southwest = new LatLng("45.434616", "4.479726");
LatLng limit_northeast = new LatLng("45.53778", "4.889763");
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress("st martin").setRegion("fr").setLanguage("fr").getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
assertTrue(geocoderResponse.getResults().size() > 1 );
geocoderRequest = new GeocoderRequestBuilder().setAddress("st martin")
.setRegion("fr")
.setLanguage("fr")
.setBounds(new LatLngBounds(limit_southwest, limit_northeast)).getGeocoderRequest();
geocoderResponse = geocoder.geocode(geocoderRequest);
for(GeocoderResult result : geocoderResponse.getResults()) {
List<GeocoderAddressComponent> addressComponents = result.getAddressComponents();
for(GeocoderAddressComponent addressComponent : addressComponents) {
if (addressComponent.getTypes().contains(GeocoderResultType.ADMINISTRATIVE_AREA_LEVEL_1.value())) {
assertTrue(addressComponent.getLongName().equals("Rhône-Alpes"));
}
}
}
}
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:24,代码来源:TestGeocoder.java
示例4: getLocationName
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
private String getLocationName(double lat, double lon) {
LatLng p = new LatLng(Double.toString(lat), Double.toString(lon));
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder()
.setLocation(p).setLanguage("en").getGeocoderRequest();
GeocodeResponse geocoderResponse;
try {
geocoderResponse = geocoder.geocode(geocoderRequest);
GeocoderResult result = geocoderResponse.getResults().get(0);
return result.getFormattedAddress();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:21,代码来源:RequestServer.java
示例5: updateGeoData
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
private void updateGeoData(LocationRecord locationRec) {
if (!keepManuallyUpdatedGeoData) {
try {
String address = locationRec.getAddress() + "," + (locationRec.getZip() != null ? locationRec.getZip() : "")
+ " " + locationRec.getCity() + "," + locationRec.getCountry();
final Geocoder geocoder = new Geocoder();
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(address).getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
if (geocoderResponse.getResults().size() != 1) {
log.error("Failed to get one result for " + address + " got " + geocoderResponse.getResults());
}
for (GeocoderResult gr : geocoderResponse.getResults()) {
LatLng latLng = gr.getGeometry().getLocation();
locationRec.setGeoLat(latLng.getLat().doubleValue());
locationRec.setGeoLng(latLng.getLng().doubleValue());
}
} catch (IOException e) {
log.error("Error accessing Geocoder API", e);
}
}
}
开发者ID:oglimmer,项目名称:lunchy,代码行数:26,代码来源:LocationResource.java
示例6: GoogleCoordinates
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
public GoogleCoordinates(final GeocoderResult result) throws GeocoderException {
super();
if (result == null) {
throw new GeocoderException("No valid geocoder result found!");
}
final GeocoderGeometry geometry = result.getGeometry();
if (geometry == null) {
throw new GeocoderException("No geometry found in Google geocoding response!");
}
final LatLng latLng = geometry.getLocation();
if (latLng == null) {
throw new GeocoderException("No latitude/longitude found in Google geocoding response!");
}
final String lonLatString = latLng.getLng().setScale(PRECISION, ROUND_HALF_EVEN).toString() + "," + latLng.getLat().setScale(6, ROUND_HALF_EVEN).toString();
setCoordinates(lonLatString);
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:21,代码来源:GoogleCoordinates.java
示例7: testGeoCoder
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
@Test
public void testGeoCoder() throws Exception {
GeoCoderEndpoint endpoint = context.getEndpoint(
"geocoder:address:current?headersOnly=true&proxyHost=localhost&proxyPort=3128&proxyAuthMethod=Basic&proxyAuthUsername=proxy&proxyAuthPassword=proxy",
GeoCoderEndpoint.class);
Geocoder geocoder = endpoint.createGeocoder();
GeocoderRequest req = new GeocoderRequest();
req.setLocation(new LatLng("45.4643", "9.1895"));
GeocodeResponse res = geocoder.geocode(req);
log.info("Response {} ", res);
}
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:GeoCoderProxyTest.java
示例8: reverseGeocoding
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
@Test
public void reverseGeocoding() throws IOException {
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setLocation(new LatLng("45.772216", "4.859242")).setLanguage("fr").getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
assertNotNull(geocoderResponse);
assertEquals(GeocoderStatus.OK, geocoderResponse.getStatus());
assertFalse(geocoderResponse.getResults().isEmpty());
final GeocoderResult geocoderResult = geocoderResponse.getResults().iterator().next();
assertTrue(geocoderResult.getFormattedAddress().contains("Rue Jean Novel"));
}
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:11,代码来源:TestGeocoder.java
示例9: getGeocode
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
static public SearchNode getGeocode(String location) {
if (location == null)
return null;
Geocoder geocoder = new Geocoder();
LatLngBounds bounds = new LatLngBounds(
new LatLng(new BigDecimal(BOUNDS_SOUTHWEST_LAT), new BigDecimal(BOUNDS_SOUTHWEST_LON)),
new LatLng(new BigDecimal(BOUNDS_NORTHEAST_LAT), new BigDecimal(BOUNDS_NORTHEAST_LON)));
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder()
.setAddress(location)
.setLanguage("de")
.setBounds(bounds)
.getGeocoderRequest();
GeocodeResponse geocoderResponse;
try {
geocoderResponse = geocoder.geocode(geocoderRequest);
if (geocoderResponse.getStatus() == GeocoderStatus.OK
& !geocoderResponse.getResults().isEmpty()) {
GeocoderResult geocoderResult =
geocoderResponse.getResults().iterator().next();
LatLng latitudeLongitude =
geocoderResult.getGeometry().getLocation();
// Only use first part of the address.
Scanner lineScanner = new Scanner(geocoderResult.getFormattedAddress());
lineScanner.useDelimiter(",");
return new SearchNode(
lineScanner.next(),
latitudeLongitude.getLat().doubleValue(),
latitudeLongitude.getLng().doubleValue());
}
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
开发者ID:dhasenfratz,项目名称:hRouting_Android,代码行数:41,代码来源:GeocodeProvider.java
示例10: execute
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
@Override
public void execute(Tuple tuple,
BasicOutputCollector outputCollector) {
Long timeInterval = tuple.getLongByField("time-interval");
List<LatLng> hz = (List<LatLng>) tuple.getValueByField("hotzones");
List<String> hotzones = asListOfStrings(hz);
try {
String key = "checkins-" + timeInterval;
String value = objectMapper.writeValueAsString(hotzones);
jedis.set(key, value);
} catch (Exception e) {
logger.error("Error persisting for time: " + timeInterval, e);
}
}
开发者ID:Storm-Applied,项目名称:C3-Heatmap,代码行数:16,代码来源:Persistor.java
示例11: asListOfStrings
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
private List<String> asListOfStrings(List<LatLng> hotzones) {
List<String> hotzonesStandard = new ArrayList<String>(hotzones.size());
for (LatLng geoCoordinate : hotzones) {
hotzonesStandard.add(geoCoordinate.toUrlValue());
}
return hotzonesStandard;
}
开发者ID:Storm-Applied,项目名称:C3-Heatmap,代码行数:8,代码来源:Persistor.java
示例12: execute
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
@Override
public void execute(Tuple tuple,
BasicOutputCollector outputCollector) {
if (isTickTuple(tuple)) {
emitHeatmap(outputCollector);
} else {
Long time = tuple.getLongByField("time");
LatLng geocode = (LatLng) tuple.getValueByField("geocode");
Long timeInterval = selectTimeInterval(time);
List<LatLng> checkins = getCheckinsForInterval(timeInterval);
checkins.add(geocode);
}
}
开发者ID:Storm-Applied,项目名称:C3-Heatmap,代码行数:15,代码来源:HeatMapBuilder.java
示例13: emitHeatmap
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
private void emitHeatmap(BasicOutputCollector outputCollector) {
Long now = System.currentTimeMillis();
Long emitUpToTimeInterval = selectTimeInterval(now);
Set<Long> timeIntervalsAvailable = heatmaps.keySet();
for (Long timeInterval : timeIntervalsAvailable) {
if (timeInterval <= emitUpToTimeInterval) {
List<LatLng> hotzones = heatmaps.remove(timeInterval);
outputCollector.emit(new Values(timeInterval, hotzones));
}
}
}
开发者ID:Storm-Applied,项目名称:C3-Heatmap,代码行数:12,代码来源:HeatMapBuilder.java
示例14: getCheckinsForInterval
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
private List<LatLng> getCheckinsForInterval(Long timeInterval) {
List<LatLng> hotzones = heatmaps.get(timeInterval);
if (hotzones == null) {
hotzones = new ArrayList<LatLng>();
heatmaps.put(timeInterval, hotzones);
}
return hotzones;
}
开发者ID:Storm-Applied,项目名称:C3-Heatmap,代码行数:9,代码来源:HeatMapBuilder.java
示例15: verifyProperValuesAreEmittedByEachBolt
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
@Test
public void verifyProperValuesAreEmittedByEachBolt() {
MkClusterParam clusterParam = new MkClusterParam();
clusterParam.setSupervisors(1);
withSimulatedTimeLocalCluster(clusterParam, new TestJob() {
@Override
public void run(ILocalCluster cluster) {
MockedSources mockedSources = new MockedSources();
mockedSources.addMockData(CHECKINS_ID, new Values(1382904793783L, "287 Hudson St New York NY 10013"));
Config config = new Config();
config.setDebug(true);
CompleteTopologyParam topologyParam = new CompleteTopologyParam();
topologyParam.setMockedSources(mockedSources);
topologyParam.setStormConf(config);
LatLng latLng = new LatLng("40.725612", "-74.00791599999999");
ArrayList<LatLng> latLngList = new ArrayList<LatLng>();
latLngList.add(latLng);
Map result = completeTopology(cluster, StormTopologyBuilder.build(), topologyParam);
assertTrue(multiseteq(new Values(new Values(1382904793783L, "287 Hudson St New York NY 10013")), readTuples(result, CHECKINS_ID)));
assertTrue(multiseteq(new Values(new Values(1382904793783L, latLng)), readTuples(result, GEOCODE_LOOKUP_ID)));
assertTrue(multiseteq(new Values(new Values(92193652L, latLngList)), readTuples(result, HEATMAP_BUILDER_ID)));
assertTrue(multiseteq(new Values(), readTuples(result, PERSISTOR_ID)));
}
});
}
开发者ID:Storm-Applied,项目名称:C3-Heatmap,代码行数:32,代码来源:TopologyTest.java
示例16: localize
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
public static String[] localize(String address){
String[] cresult=new String[]{"0.0","0.0"};
try {
if (address!=null && address.trim().length()>0){
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(address).setLanguage("en").getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
List<GeocoderResult> results = geocoderResponse.getResults();
if (results!=null && !results.isEmpty()){
for (GeocoderResult result : results) {
LatLng location = result.getGeometry().getLocation();
//System.out.println(address+" "+ location.getLat() + "," + location.getLng());
if (location.getLat()!=null ){
cresult[0]=""+location.getLat();
}else{
cresult[0]="0.0";
}
if (location.getLng()!=null ){
cresult[1]=""+location.getLng();
}else{
cresult[1]="0.0";
}
}
}else{
cresult[0]="0.0";
cresult[1]="0.0";
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
return cresult;
}
开发者ID:SmartInfrastructures,项目名称:xipi,代码行数:38,代码来源:GoogleUtil.java
示例17: getGeoByPubLatLng
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
private static void getGeoByPubLatLng(Pub pub, final Geocoder geocoder) {
GeocoderRequest request = new GeocoderRequestBuilder()
.setAddress(pub.getLocal())
.setLocation(new LatLng(new BigDecimal(pub.getLat()), new BigDecimal(pub.getLng())))
.setLanguage("en")
.getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
if (response.getStatus().equals(GeocoderStatus.OK)) {
List<GeocoderResult> results = response.getResults();
for (GeocoderResult geoResult : results) {
List<GeocoderAddressComponent> addressComponents = geoResult.getAddressComponents();
for (GeocoderAddressComponent address : addressComponents) {
if (address.getTypes().contains("locality")) {
pub.setCity(address.getLongName());
}
if (address.getTypes().contains("administrative_area_level_1")) {
pub.setState(address.getLongName());
}
if (address.getTypes().contains("country")) {
pub.setCountry(address.getLongName());
}
}
}
} else {
log.info(response.getStatus().name());
}
}
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:31,代码来源:GeocoderUtils.java
示例18: getGeoByLatLng
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
public static Map<String, String> getGeoByLatLng(Double lat, Double lng) {
Map<String, String> map = new HashMap<String, String>();
final Geocoder geocoder = new Geocoder();
GeocoderRequest request = new GeocoderRequestBuilder()
.setLocation(new LatLng(new BigDecimal(lat), new BigDecimal(lng)))
.setLanguage("en")
.getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
if (response.getStatus().equals(GeocoderStatus.OK)) {
List<GeocoderResult> results = response.getResults();
for (GeocoderResult geoResult : results) {
List<GeocoderAddressComponent> addressComponents = geoResult.getAddressComponents();
for (GeocoderAddressComponent address : addressComponents) {
if (address.getTypes().contains("locality")) {
map.put("CITY", address.getLongName());
}
if (address.getTypes().contains("administrative_area_level_1")) {
map.put("STATE", address.getLongName());
}
if (address.getTypes().contains("country")) {
map.put("COUNTRY", address.getLongName());
}
}
}
} else {
log.info(response.getStatus().name());
}
return map;
}
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:36,代码来源:GeocoderUtils.java
示例19: getLatLongZip
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
private LatLong getLatLongZip( String zipcode ) {
final Geocoder geocoder = new Geocoder();
GeocoderRequest request = new GeocoderRequestBuilder().setAddress(zipcode).setLanguage("en").getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
LatLong ll = null;
if( response != null && response.getStatus() == GeocoderStatus.OK ) {
for( GeocoderResult geoResult : response.getResults() ) {
LatLng googLatLong = geoResult.getGeometry().getLocation();
ll = new LatLong( googLatLong.getLat().floatValue(), googLatLong.getLng().floatValue() );
}
}
return ll;
}
开发者ID:aws-reinvent-hackathon-2013-team,项目名称:UnitedWayRESTBackend,代码行数:15,代码来源:VolunteerService.java
示例20: geocode
import com.google.code.geocoder.model.LatLng; //导入依赖的package包/类
public static GeoPt geocode(String address) throws GeocodeFailedException, GeocodeNotFoundException {
// The underlying geocoder library fails if it receives an empty address.
if (address.trim().isEmpty()) {
throw new GeocodeFailedException(address, GeocoderStatus.INVALID_REQUEST);
}
String cacheKey = "geocode:" + address;
CacheProxy cache = new CacheProxy();
Object cacheEntry = cache.get(cacheKey);
// Backwards comparison -- cacheEntry may be null
if (INVALID_LOCATION.equals(cacheEntry)) {
throw new GeocodeNotFoundException(address);
}
if (cacheEntry != null) {
return (GeoPt) cacheEntry;
}
Geocoder geocoder = new Geocoder(); // TODO: Use Maps for Business?
GeocoderRequest request = new GeocoderRequestBuilder().setAddress(address).getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
GeocoderStatus status = response.getStatus();
if (status == GeocoderStatus.ZERO_RESULTS) {
cache.put(cacheKey, INVALID_LOCATION);
throw new GeocodeNotFoundException(address);
} else if (status != GeocoderStatus.OK) {
// We've encountered a temporary error, so return without caching the missing point.
throw new GeocodeFailedException(address, response.getStatus());
} else {
LatLng location = response.getResults().get(0).getGeometry().getLocation();
GeoPt geoPt = new GeoPt(location.getLat().floatValue(), location.getLng().floatValue());
cache.put(cacheKey, geoPt);
return geoPt;
}
}
开发者ID:openmash,项目名称:mashmesh,代码行数:38,代码来源:GeoUtils.java
注:本文中的com.google.code.geocoder.model.LatLng类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论