当前位置: 首页>>代码示例>>Java>>正文


Java GeocoderRequest类代码示例

本文整理汇总了Java中com.google.code.geocoder.model.GeocoderRequest的典型用法代码示例。如果您正苦于以下问题:Java GeocoderRequest类的具体用法?Java GeocoderRequest怎么用?Java GeocoderRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GeocoderRequest类属于com.google.code.geocoder.model包,在下文中一共展示了GeocoderRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculateCoordinateForAddress

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的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: locationToCoordinate

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
public GeocoderGeometry locationToCoordinate(String location) throws IOException {
    GeocoderGeometry coordinate = null;

    if (location != null && !location.isEmpty()) {
        GeocoderRequest request = new GeocoderRequest();
        request.setAddress(location);

        GeocodeResponse response = geocoder.geocode(request);
        if (response.getStatus() == GeocoderStatus.OK) {
            List<GeocoderResult> results = response.getResults();

            for (GeocoderResult result : results) {
                GeocoderGeometry geometry = result.getGeometry();
                coordinate = geometry;
                break;
            }
        }
    }

    return coordinate;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:22,代码来源:GoogleGeocoderService.java

示例3: coordinateToLocation

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
public String coordinateToLocation(GeocoderGeometry coordinate) throws IOException {
    String location = null;

    if (coordinate != null) {
        GeocoderRequest request = new GeocoderRequest();
        request.setLocation(coordinate.getLocation());
        request.setBounds(coordinate.getBounds());

        GeocodeResponse response = geocoder.geocode(request);
        if (response.getStatus() == GeocoderStatus.OK) {
            List<GeocoderResult> results = response.getResults();
            for (GeocoderResult result : results) {
                location = result.getFormattedAddress();
                break;
            }
        }
    }

    return location;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:21,代码来源:GoogleGeocoderService.java

示例4: testAccurateSearch

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的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

示例5: testBoundingCity

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的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

示例6: testSitraObject

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
@Test
public void testSitraObject() throws IOException{
	String obt_domaine_skiable = "Domaines skiables";
	String obt_patrimoine_naturel = "Patrimoine Naturel";
	String obt_fetes_manifestations = "Fêtes et Manisfestations";
	
	GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(obt_domaine_skiable).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
	assertEquals(geocoderResponse.getStatus(), GeocoderStatus.ZERO_RESULTS);
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress(obt_patrimoine_naturel).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertEquals(geocoderResponse.getStatus(), GeocoderStatus.ZERO_RESULTS);
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress(obt_fetes_manifestations).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertEquals(geocoderResponse.getStatus(), GeocoderStatus.ZERO_RESULTS);
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:19,代码来源:TestGeocoder.java

示例7: getLocationName

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的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

示例8: updateGeoData

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的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

示例9: getCoordinates

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
@Override
public synchronized Coordinates getCoordinates(final String address) throws GeocoderException {
    ensureInitialized();

    final GeocoderRequest request = new GeocoderRequestBuilder().setAddress(address).setLanguage("en").getGeocoderRequest();
    final GeocodeResponse response = m_geocoder.geocode(request);

    switch (response.getStatus()) {
    case OK:
        return new GoogleCoordinates(response.getResults().get(0));
    case OVER_QUERY_LIMIT:
        throw new TemporaryGeocoderException("Failed to get coordinates for " + address + " using the Google Geocoder.  You have exceeded the daily usage limit.");
    case ERROR:
    case INVALID_REQUEST:
    case REQUEST_DENIED:
    case UNKNOWN_ERROR:
    case ZERO_RESULTS:
    default:
        throw new GeocoderException("Failed to get coordinates for " + address + " using Google Geocoder.  Response was: " + response.getStatus().toString());
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:22,代码来源:GoogleGeocoderService.java

示例10: getGeoPt

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
@Nullable
public static GeoPt getGeoPt(String addressStr) {
  // TODO(avaliani): use an api key to avoid geocoding quota limits
  final Geocoder geocoder = new Geocoder();
  GeocoderRequest geocoderRequest = new GeocoderRequestBuilder()
    .setAddress(addressStr)
    .setLanguage("en")
    .getGeocoderRequest();
  GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);

  if (geocoderResponse.getStatus() == GeocoderStatus.OK) {
    GeocoderResult firstResult = geocoderResponse.getResults().get(0);
    return new GeoPt(
      firstResult.getGeometry().getLocation().getLat().floatValue(),
      firstResult.getGeometry().getLocation().getLng().floatValue());
  } else {
    log.log(GEOCODE_LOG_LEVEL,
      "Geocoding failed: status=" + geocoderResponse.getStatus() + ", " +
        "response=" + geocoderResponse);

    // TODO(avaliani): Properly handle geopt encoding failures. Retrying in cases where
    //   the error is over quota.
    return null;
  }
}
 
开发者ID:karma-exchange-org,项目名称:karma-exchange,代码行数:26,代码来源:GeocodingService.java

示例11: testGeoCoder

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的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

示例12: testURL

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
@Test
public void testURL() throws IOException {
	//Obtenir une réponse
	GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress("Lyon, France").setLanguage("fr").getGeocoderRequest();
	GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
	assertEquals(geocoderResponse.getStatus(), GeocoderStatus.OK);
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:8,代码来源:TestGeocoder.java

示例13: reverseGeocoding

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的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

示例14: testTourismName

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
@Test
public void testTourismName() throws IOException {
	String domaine_skiable = "La croix fry"; //Domaine skiable
	String restaurant = "Mc Donalds";
	String fete = "Fêtes des lumières";
	String parc = "Parc de la tête d'or";
	
	GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(domaine_skiable).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
	assertFalse(geocoderResponse.getResults().iterator().next().getTypes().contains(GeocoderResultType.POINT_OF_INTEREST.value()));
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress(restaurant).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertFalse(geocoderResponse.getResults().iterator().next().getTypes().contains(GeocoderResultType.POINT_OF_INTEREST.value()));
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress(fete).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertEquals(geocoderResponse.getStatus(), GeocoderStatus.ZERO_RESULTS);
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress("restaurant Lyon").setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertFalse(geocoderResponse.getResults().iterator().next().getTypes().contains(GeocoderResultType.POINT_OF_INTEREST.value()));
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress(parc).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertTrue(geocoderResponse.getResults().iterator().next().getTypes().contains(GeocoderResultType.PARK.value()));
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress("Aéroport").setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertTrue(geocoderResponse.getResults().iterator().next().getTypes().contains(GeocoderResultType.AIRPORT.value()));
	
	geocoderRequest = new GeocoderRequestBuilder().setAddress("L'Yon, Vendée, Pays de la Loire").setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertTrue(geocoderResponse.getResults().iterator().next().getTypes().contains(GeocoderResultType.NATURAL_FEATURE.value()));
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:36,代码来源:TestGeocoder.java

示例15: testAutocompleteAdress

import com.google.code.geocoder.model.GeocoderRequest; //导入依赖的package包/类
@Test
public void testAutocompleteAdress() throws IOException {
	String adress = "place foch";
	
	GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(adress).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
	assertTrue(geocoderResponse.getResults().size() == 10);
	
	adress = "rue  Victor Hugo";
	geocoderRequest = new GeocoderRequestBuilder().setAddress(adress).setRegion("fr").setLanguage("fr").getGeocoderRequest();
	geocoderResponse = geocoder.geocode(geocoderRequest);
	assertTrue(geocoderResponse.getResults().size() == 10);
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:14,代码来源:TestGeocoder.java


注:本文中的com.google.code.geocoder.model.GeocoderRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。