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


Java GeocodingResult类代码示例

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


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

示例1: locate

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
@Override
public GeoLocationResponse locate(final Double latitude, final Double longitude) {
    if (latitude == null || longitude == null) {
        LOGGER.debug("latitude/longitude must not be null in order for geolocation to proceed");
        return null;
    }

    final GeoLocationResponse r = new GeoLocationResponse();
    r.setLatitude(latitude);
    r.setLongitude(longitude);

    final LatLng latlng = new LatLng(latitude, longitude);
    try {
        final GeocodingResult[] results = GeocodingApi.reverseGeocode(this.context, latlng).await();
        if (results != null && results.length > 0) {
            Arrays.stream(results)
                    .map(result -> result.formattedAddress)
                    .forEach(r::addAddress);

            return r;
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return r;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:27,代码来源:GoogleMapsGeoLocationService.java

示例2: lookupAddr

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
public static String lookupAddr(String establishment) throws ApiException, InterruptedException, IOException {
	
	//set up key
	GeoApiContext lookupDoodad = new GeoApiContext.Builder()
		    .apiKey(API_KEY)
		    .build();
		GeocodingResult[] results =  GeocodingApi.geocode(lookupDoodad,
		    establishment).await();
		
		//converts results into usable address
		
		String address = (results[0].formattedAddress);
	
	return address;
}
 
开发者ID:Celethor,项目名称:CS360proj1,代码行数:16,代码来源:EarthSearch.java

示例3: lookupCoord

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
public static LatLng lookupCoord(String establishment) throws ApiException, InterruptedException, IOException {
		
	//set up key
	GeoApiContext lookupDoodad = new GeoApiContext.Builder()
		    .apiKey(API_KEY)
		    .build();
	GeocodingResult[] results =  GeocodingApi.geocode(lookupDoodad,
	  establishment).await();
			
		//converts results into usable Coordinates
	
		LatLng coords = (results[0].geometry.location);
			//System.out.println(results[0].geometry.location);
	return coords;
}
 
开发者ID:Celethor,项目名称:CS360proj1,代码行数:16,代码来源:EarthSearch.java

示例4: Place

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
public Place(int n, String address, double demand, double tis, double tie, double st) {
    ParseLocalDB();
    JSONArray coords = getPlaceCoordsFromLocalDB(address);
    if (coords == null) {
        GeocodingResult[] results = new GeocodingResult[0];
        try {
            results = GeocodingApi.geocode(Place.context, address).language("ru").await();
            this.lat = results[0].geometry.location.lat;
            this.lng = results[0].geometry.location.lng;
            this.address = results[0].formattedAddress;
            this.xs = this.xs_display = GoogleMapsProjection.latToYWorld(this.lat);
            this.ys = this.ys_display = GoogleMapsProjection.lonToXWorld(this.lng);
        } catch (Exception e) {
            e.printStackTrace();
            this.address = address;
            this.xs = this.xs_display = 0;
            this.ys = this.ys_display = 0;
        }
    } else {
        this.lat = Double.parseDouble((String) coords.get(0));
        this.lng = Double.parseDouble((String) coords.get(1));
        this.address = address;
        this.xs = this.xs_display = GoogleMapsProjection.latToYWorld(this.lat);
        this.ys = this.ys_display = GoogleMapsProjection.lonToXWorld(this.lng);
    }
    this.demand = demand;
    this.time_interval_start = tis;
    this.time_interval_end = tie;
    this.service_time = st;
    this.number = n;
}
 
开发者ID:MrBadge,项目名称:Parallel_Ant_Colony,代码行数:32,代码来源:Place.java

示例5: Address

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
@SneakyThrows
public Address(String address) {
    this.address = address;
    if (address != null && geoApiContext != null) {
        GeocodingResult[] results = GeocodingApi.geocode(geoApiContext, address).await();
        if (results.length > 0) {
            GeocodingResult result = results[0];
            for (AddressComponent component : result.addressComponents) {
                List<AddressComponentType> types = Arrays.asList(component.types);
                if (types.contains(AddressComponentType.COUNTRY)) {
                    this.country = component.longName;
                }
                if (types.contains(AddressComponentType.LOCALITY)) {
                    this.city = component.longName;
                }
                if (types.contains(AddressComponentType.POSTAL_CODE)) {
                    this.postalCode = component.longName;
                }
            }
            this.latitude = result.geometry.location.lat;
            this.longitude = result.geometry.location.lng;
        }
    }
}
 
开发者ID:eventsourcing,项目名称:es4j,代码行数:25,代码来源:Address.java

示例6: testSimpleReverseGeocode

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
/**
 * Simple reverse geocoding. <a
 * href="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452">Reverse
 * geocode (40.714224,-73.961452)</a>.
 */
@Test
public void testSimpleReverseGeocode() throws Exception {
  try (LocalTestServerContext sc = new LocalTestServerContext(simpleReverseGeocodeResponse)) {
    LatLng latlng = new LatLng(40.714224, -73.961452);
    GeocodingResult[] results = GeocodingApi.newRequest(sc.context).latlng(latlng).await();

    assertNotNull(results);
    assertEquals("277 Bedford Ave, Brooklyn, NY 11211, USA", results[0].formattedAddress);
    assertEquals("277", results[0].addressComponents[0].longName);
    assertEquals("277", results[0].addressComponents[0].shortName);
    assertEquals(AddressComponentType.STREET_NUMBER, results[0].addressComponents[0].types[0]);
    assertEquals(AddressType.STREET_ADDRESS, results[0].types[0]);

    sc.assertParamValue(latlng.toUrlValue(), "latlng");
  }
}
 
开发者ID:googlemaps,项目名称:google-maps-services-java,代码行数:22,代码来源:GeocodingApiTest.java

示例7: testReverseGeocodeWithKitaWard

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
/** Testing Kita Ward reverse geocode. */
@Test
public void testReverseGeocodeWithKitaWard() throws Exception {
  try (LocalTestServerContext sc =
      new LocalTestServerContext(reverseGeocodeWithKitaWardResponse)) {
    LatLng location = new LatLng(35.03937, 135.729243);
    GeocodingResult[] results = GeocodingApi.newRequest(sc.context).latlng(location).await();

    assertNotNull(results);
    assertEquals(
        "Japan, 〒603-8361 Kyōto-fu, Kyōto-shi, Kita-ku, Kinkakujichō, 1 北山鹿苑寺金閣寺",
        results[0].formattedAddress);
    assertEquals("Kita Ward", results[3].addressComponents[0].shortName);
    assertEquals("Kita Ward", results[3].addressComponents[0].longName);
    assertEquals(AddressComponentType.LOCALITY, results[3].addressComponents[0].types[0]);
    assertEquals(AddressComponentType.POLITICAL, results[3].addressComponents[0].types[1]);
    assertEquals(AddressComponentType.WARD, results[3].addressComponents[0].types[2]);

    sc.assertParamValue(location.toUrlValue(), "latlng");
  }
}
 
开发者ID:googlemaps,项目名称:google-maps-services-java,代码行数:22,代码来源:GeocodingApiTest.java

示例8: testErrorResponseRetries

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
@Test
public void testErrorResponseRetries() throws Exception {
  // Set up mock responses
  MockResponse errorResponse = createMockBadResponse();
  MockResponse goodResponse = createMockGoodResponse();

  server.enqueue(errorResponse);
  server.enqueue(goodResponse);
  server.start();

  // Build the context under test
  setMockBaseUrl();

  // Execute
  GeocodingResult[] result =
      builder.build().get(new ApiConfig("/"), GeocodingApi.Response.class, "k", "v").await();
  assertEquals(1, result.length);
  assertEquals(
      "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA", result[0].formattedAddress);

  server.shutdown();
}
 
开发者ID:googlemaps,项目名称:google-maps-services-java,代码行数:23,代码来源:GeoApiContextTest.java

示例9: getGeoCodedLocation

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
/**
 * With the supplied address, this method uses the Google Maps API to retrieve geocoded
 * information, such as coordinates, postalcode, city, country etc.
 *
 * @param address       The address to geocode.
 * @return              An EventLocation object containing all geocoded data.
 */
static EventLocation getGeoCodedLocation(String address) {

    EventLocation eventLocation = new EventLocation();

    // Temporary API key
    final String API_KEY = "AIzaSyAM9tW28Kcfem-zAIyyPnnPnyqL1WY5TGo";

    GeoApiContext context = new GeoApiContext().setApiKey(API_KEY);
    GeocodingApiRequest request = GeocodingApi.newRequest(context).address(address);

    try {
        GeocodingResult[] results = request.await();

        List<Double> latlng = new ArrayList<>();
        latlng.add(results[0].geometry.location.lng);
        latlng.add(results[0].geometry.location.lat);

        EventLocationCoordinates eventLocationCoordinates = new EventLocationCoordinates();
        eventLocationCoordinates.setCoordinates(latlng);
        eventLocation.setCoordinates(eventLocationCoordinates);
        eventLocation.setAddress(address);
        eventLocation.setParsedAddress(results[0].formattedAddress);

        for (AddressComponent addressComponent : results[0].addressComponents) {
            switch (addressComponent.types[0]) {
                case POSTAL_CODE:
                    // Remove any white space from postal code
                    String postalCode = addressComponent.longName
                            .replaceAll("\\s+","");
                    eventLocation.setPostalCode(postalCode);
                    break;
                case LOCALITY:
                    eventLocation.setCity(addressComponent.longName);
                    break;
                case POSTAL_TOWN:
                    eventLocation.setCity(addressComponent.longName);
                    break;
                case ADMINISTRATIVE_AREA_LEVEL_1:
                    eventLocation.setCounty(addressComponent.longName);
                    break;
                case COUNTRY:
                    eventLocation.setCountry(addressComponent.shortName);
                    break;
                default:
                    break;
            }
        }

    } catch (Exception e) {
        // Handle error
    }

    return eventLocation;
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:62,代码来源:GeoCodeHandler.java

示例10: reverseGeocode

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
/**
 * Sends a reverse geocode request obtaining the district identifier.
 *
 * @param latitude  latitude value
 * @param longitude longitude value
 * @throws Exception if a geocoding error occurred
 */
private void reverseGeocode(final double latitude, final double longitude) throws Exception {
    final GeoApiContext context = new GeoApiContext.Builder()
            .apiKey(KEY)
            .build();
    final LatLng latlng = new LatLng(latitude, longitude);
    final GeocodingResult[] results;
    try {
        results = GeocodingApi.reverseGeocode(context, latlng).await();
        final Gson gson = new GsonBuilder().setPrettyPrinting().create();
        this.response = gson.toJson(results[0].addressComponents);
    } catch (final Exception e) {
        throw e;
    }
}
 
开发者ID:SofiaRosetti,项目名称:S3-16-d-rescue,代码行数:22,代码来源:GeocodingImpl.java

示例11: getLocationOfMentor

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
public Point getLocationOfMentor(Mentor mentor) {
	GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyC9hT7x8gTBdXcTSEy6XU_EWpr_WDe8lSY");
	try {
		String address = "";
		if (mentor.getAddress1() != null && mentor.getAddress1().length() > 0 ) {
			address += (address.length() > 0 ? ", " : "") + mentor.getAddress1();
		}
		if (mentor.getAddress2() != null && mentor.getAddress2().length() > 0 ) {
			address += (address.length() > 0 ? ", " : "") + mentor.getAddress2();
		}
		if (mentor.getZip() != null && mentor.getZip().length() > 0 ) {
			address += (address.length() > 0 ? ", " : "") + mentor.getZip();
		}
		if (mentor.getCity() != null && mentor.getCity().length() > 0 ) {
			address += (address.length() > 0 ? ", " : "") + mentor.getCity();
		}
		if (mentor.getState() != null && mentor.getState().length() > 0 ) {
			address += (address.length() > 0 ? ", " : "") + mentor.getState();
		}
		if (mentor.getCountryId() != null && mentor.getCountryId().getName() != null && mentor.getCountryId().getName().length() > 0 ) {
			address += (address.length() > 0 ? ", " : "") + mentor.getCountryId().getName();
		}
		if (address.length() > 0) {
			GeocodingResult[] results =  GeocodingApi.geocode(context, address).await();
			return new Point(results[0].geometry.location.lat, results[0].geometry.location.lng);
		} else {
			log.error("Unable to geocode address of " + mentor.getFullName() + ": No address available");
			return null;
		}
	} catch (Exception e) {
		log.error("Unable to geocode address of " + mentor.getFullName() + ": " + e.toString());
		return null;
	}

}
 
开发者ID:sapmentors,项目名称:lemonaid,代码行数:36,代码来源:MentorUtils.java

示例12: getPublicLocationOfMentor

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
public Point getPublicLocationOfMentor(Mentor mentor) {
	GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyC9hT7x8gTBdXcTSEy6XU_EWpr_WDe8lSY");
	try {
		String address = "";
		if (mentor.getAddress1() != null && mentor.getAddress1().length() > 0 && mentor.getAddress1Public()) {
			address += (address.length() > 0 ? ", " : "") + mentor.getAddress1();
		}
		if (mentor.getAddress2() != null && mentor.getAddress2().length() > 0 && mentor.getAddress2Public()) {
			address += (address.length() > 0 ? ", " : "") + mentor.getAddress2();
		}
		if (mentor.getZip() != null && mentor.getZip().length() > 0 && mentor.getZipPublic()) {
			address += (address.length() > 0 ? ", " : "") + mentor.getZip();
		}
		if (mentor.getCity() != null && mentor.getCity().length() > 0 && mentor.getCityPublic()) {
			address += (address.length() > 0 ? ", " : "") + mentor.getCity();
		}
		if (mentor.getState() != null && mentor.getState().length() > 0 && mentor.getStatePublic()) {
			address += (address.length() > 0 ? ", " : "") + mentor.getState();
		}
		if (mentor.getCountryId() != null && mentor.getCountryId().getName() != null && mentor.getCountryId().getName().length() > 0 && mentor.getCountryPublic()) {
			address += (address.length() > 0 ? ", " : "") + mentor.getCountryId().getName();
		}
		if (address.length() > 0) {
			GeocodingResult[] results =  GeocodingApi.geocode(context, address).await();
			return new Point(results[0].geometry.location.lat, results[0].geometry.location.lng);
		} else {
			log.error("Unable to geocode address of " + mentor.getFullName() + ": No address available");
			return null;
		}
	} catch (Exception e) {
		log.error("Unable to geocode address of " + mentor.getFullName() + ": " + e.toString());
		return null;
	}

}
 
开发者ID:sapmentors,项目名称:lemonaid,代码行数:36,代码来源:MentorUtils.java

示例13: getLocationOfRestaurant

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
/**
 * Gets the location of restaurant using the Google Geocoding API.
 *
 * @param restaurant
 * 			Restaurant from which to get the location.
 * @return the location of restaurant
 */
private String getLocationOfRestaurant(Restaurant restaurant, HttpServletRequest request) {
	
	// Replace the API key below with a valid API key.
	GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyAvO9bl1Yi2hn7mkTSniv5lXaPRii1JxjI");
	GeocodingApiRequest req = GeocodingApi.newRequest(context).address(String.format("%1$s %2$s, %3$s %4$s", restaurant.getStreetNumber(), restaurant.getStreet(), restaurant.getZip(), restaurant.getCity()));

	try {
		GeocodingResult[] result = req.await();
		if (result != null && result.length > 0) {
			// Handle successful request.
			GeocodingResult firstMatch = result[0];
			if (firstMatch.geometry != null && firstMatch.geometry.location != null) {
				restaurant.setLocationLatitude((float) firstMatch.geometry.location.lat);
				restaurant.setLocationLongitude((float) firstMatch.geometry.location.lng);
			} else {
				return messageSource.getMessage("restaurant.addressNotResolveable", null, Locale.getDefault());
			}
		} else {
			return messageSource.getMessage("restaurant.addressNotFound", null, Locale.getDefault());
		}
	} catch (Exception e) {
		LOGGER.error(LogUtils.getExceptionMessage(request, Thread.currentThread().getStackTrace()[1].getMethodName(), e));
		return messageSource.getMessage("restaurant.googleApiError", new String[] { e.getMessage() }, Locale.getDefault());
	}
	return null;
}
 
开发者ID:andju,项目名称:findlunch,代码行数:34,代码来源:RestaurantController.java

示例14: geocode

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
@Timed
@Override
public GeocodingResult[] geocode(
        @Nonnull String address
) throws Exception {
    LOGGER.debug("geocode called: address={}", address);
    requireNonNull(address, "address cannot be null");
    return GeocodingApi.geocode(context, address).await();
}
 
开发者ID:healthbam,项目名称:healthbam,代码行数:10,代码来源:DefaultGoogleGeocodeClient.java

示例15: testGetLocationInfo

import com.google.maps.model.GeocodingResult; //导入依赖的package包/类
@Test
public void testGetLocationInfo() throws Exception {
    String zipCode = "30332";

    Program program = new Program();
    program.setCity("Atlanta");
    program.setState("GA");
    program.setStreetAddress("123 Peachtree St.");
    program.setZipCode(zipCode);

    String expectedFormattedAddress = "123 Peachtree St. Atlanta, GA 30332";

    LocationInfo expected = new LocationInfo();
    expected.setLngLat("-1.23456789,9.87654321");
    expected.setZipCode(zipCode);

    AddressComponent addressComponent = new AddressComponent();
    addressComponent.longName = zipCode;
    addressComponent.types = new AddressComponentType[] {AddressComponentType.POSTAL_CODE};
    LatLng latLng = new LatLng(9.87654321, -1.23456789);
    Geometry geometry = new Geometry();
    geometry.location = latLng;
    GeocodingResult geocodingResult = new GeocodingResult();
    geocodingResult.geometry = geometry;
    geocodingResult.addressComponents = new AddressComponent[] {addressComponent};
    GeocodingResult[] expectedGeocodingResult = new GeocodingResult[] {geocodingResult};

    /* Train the mocks. */
    when(googleGeocodeClient.geocode(expectedFormattedAddress)).thenReturn(expectedGeocodingResult);

    /* Make the call. */
    LocationInfo actual = toTest.getLocationInfo(program);

    /* Verify the results. */
    assertEquals(expected, actual);
}
 
开发者ID:healthbam,项目名称:healthbam,代码行数:37,代码来源:GoogleGeocodeServiceTest.java


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