本文整理汇总了Java中com.google.maps.model.TravelMode类的典型用法代码示例。如果您正苦于以下问题:Java TravelMode类的具体用法?Java TravelMode怎么用?Java TravelMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TravelMode类属于com.google.maps.model包,在下文中一共展示了TravelMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDriveDist
import com.google.maps.model.TravelMode; //导入依赖的package包/类
public static long getDriveDist(String addrOne, String addrTwo) throws ApiException, InterruptedException, IOException{
//set up key
GeoApiContext distCalcer = new GeoApiContext.Builder()
.apiKey(API_KEY)
.build();
DistanceMatrixApiRequest req = DistanceMatrixApi.newRequest(distCalcer);
DistanceMatrix result = req.origins(addrOne)
.destinations(addrTwo)
.mode(TravelMode.DRIVING)
.avoid(RouteRestriction.TOLLS)
.language("en-US")
.await();
long distApart = result.rows[0].elements[0].distance.inMeters;
return distApart;
}
示例2: distanceMatrix
import com.google.maps.model.TravelMode; //导入依赖的package包/类
public static void distanceMatrix(String[] origins, String[] destinations) throws ApiException, InterruptedException, IOException{
GeoApiContext context = new GeoApiContext.Builder()
.apiKey(API_KEY)
.build();
DistanceMatrixApiRequest req=DistanceMatrixApi.newRequest(context);
DistanceMatrix t=req.origins(origins).destinations(destinations).mode(TravelMode.DRIVING).await();
//long[][] array=new long[origins.length][destinations.length];
File file=new File("Matrix.txt");
FileOutputStream out=new FileOutputStream(file);
DataOutputStream outFile=new DataOutputStream(out);
for(int i=0;i<origins.length;i++){
for(int j=0;j<destinations.length;j++){
//System.out.println(t.rows[i].elements[j].distance.inMeters);
outFile.writeLong(t.rows[i].elements[j].distance.inMeters);
}
}
outFile.close();
}
示例3: getDistanceMatrix
import com.google.maps.model.TravelMode; //导入依赖的package包/类
public static DistanceMatrix getDistanceMatrix(boolean driving) {
String[] shipments = new String[1 + ShipmentController.getItems().size()];
shipments[0] = PathController.getWalkingPO().getAddress();
for (int i = 0; i < ShipmentController.getItems().size(); i++) {
shipments[i + 1] = ShipmentController.getItems().get(i).getAddress();
}
GeoApiContext context = new GeoApiContext().setApiKey(XFacteur.GOOGLE_API_KEY);
DistanceMatrixApiRequest req = DistanceMatrixApi.getDistanceMatrix(context, shipments, shipments);
req.language("fr-FR");
req.units(Unit.METRIC);
req.mode(driving ? TravelMode.DRIVING : TravelMode.WALKING);
try {
return req.await();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例4: getDirections
import com.google.maps.model.TravelMode; //导入依赖的package包/类
public void getDirections() {
this.fromLatLngCurr = fromLatLngNew;
this.toLatLngCurr = toLatLngNew;
this.fromTitleCurr = fromTitleNew;
this.toTitleCurr = toTitleNew;
try {
calculatedRoutes = DirectionsApi.newRequest(context)
.alternatives(true)
.mode(TravelMode.WALKING)
.origin(MapUtils.getModelLatLngFromGms(fromLatLngCurr))
.destination(MapUtils.getModelLatLngFromGms(toLatLngCurr))
.await();
} catch (Exception e) {
e.printStackTrace();
}
clearMarkersFromMap();
drawRouteMarkers();
updateBounds();
}
示例5: validateRequest
import com.google.maps.model.TravelMode; //导入依赖的package包/类
@Override
protected void validateRequest() {
if (!params().containsKey("origin")) {
throw new IllegalArgumentException("Request must contain 'origin'");
}
if (!params().containsKey("destination")) {
throw new IllegalArgumentException("Request must contain 'destination'");
}
if (TravelMode.TRANSIT.toString().equals(params().get("mode"))
&& (params().containsKey("arrival_time") && params().containsKey("departure_time"))) {
throw new IllegalArgumentException(
"Transit request must not contain both a departureTime and an arrivalTime");
}
if (params().containsKey("traffic_model") && !params().containsKey("departure_time")) {
throw new IllegalArgumentException(
"Specifying a traffic model requires that departure time be provided.");
}
}
示例6: testLanguageParameter
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/**
* Test the language parameter.
*
* <p>Sample request: <a
* href="http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR">
* origins: Vancouver BC|Seattle, destinations: San Francisco|Victoria BC, mode: bicycling,
* language: french</a>.
*/
@Test
public void testLanguageParameter() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) {
String[] origins = new String[] {"Vancouver BC", "Seattle"};
String[] destinations = new String[] {"San Francisco", "Victoria BC"};
DistanceMatrixApi.newRequest(sc.context)
.origins(origins)
.destinations(destinations)
.mode(TravelMode.BICYCLING)
.language("fr-FR")
.await();
sc.assertParamValue(StringUtils.join(origins, "|"), "origins");
sc.assertParamValue(StringUtils.join(destinations, "|"), "destinations");
sc.assertParamValue(TravelMode.BICYCLING.toUrlValue(), "mode");
sc.assertParamValue("fr-FR", "language");
}
}
示例7: testTransitWithoutSpecifyingTime
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/** Test transit without arrival or departure times specified. */
@Test
public void testTransitWithoutSpecifyingTime() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) {
String[] origins =
new String[] {"Fisherman's Wharf, San Francisco", "Union Square, San Francisco"};
String[] destinations =
new String[] {"Mikkeller Bar, San Francisco", "Moscone Center, San Francisco"};
DistanceMatrixApi.newRequest(sc.context)
.origins(origins)
.destinations(destinations)
.mode(TravelMode.TRANSIT)
.await();
sc.assertParamValue(StringUtils.join(origins, "|"), "origins");
sc.assertParamValue(StringUtils.join(destinations, "|"), "destinations");
sc.assertParamValue(TravelMode.TRANSIT.toUrlValue(), "mode");
}
}
示例8: testDurationInTrafficWithTrafficModel
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/** Test duration in traffic with traffic model set. */
@Test
public void testDurationInTrafficWithTrafficModel() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) {
final long ONE_HOUR_MILLIS = 60 * 60 * 1000;
DistanceMatrixApi.newRequest(sc.context)
.origins("Fisherman's Wharf, San Francisco")
.destinations("San Francisco International Airport, San Francisco, CA")
.mode(TravelMode.DRIVING)
.trafficModel(TrafficModel.PESSIMISTIC)
.departureTime(new DateTime(System.currentTimeMillis() + ONE_HOUR_MILLIS))
.await();
sc.assertParamValue("Fisherman's Wharf, San Francisco", "origins");
sc.assertParamValue("San Francisco International Airport, San Francisco, CA", "destinations");
sc.assertParamValue(TravelMode.DRIVING.toUrlValue(), "mode");
sc.assertParamValue(TrafficModel.PESSIMISTIC.toUrlValue(), "traffic_model");
}
}
示例9: testResponseTimesArePopulatedCorrectly
import com.google.maps.model.TravelMode; //导入依赖的package包/类
@Test
public void testResponseTimesArePopulatedCorrectly() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext(responseTimesArePopulatedCorrectly)) {
DirectionsResult result =
DirectionsApi.newRequest(sc.context)
.mode(TravelMode.TRANSIT)
.origin("483 George St, Sydney NSW 2000, Australia")
.destination("182 Church St, Parramatta NSW 2150, Australia")
.await();
assertEquals(1, result.routes.length);
assertEquals(1, result.routes[0].legs.length);
DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm a");
assertEquals("1:54 pm", fmt.print(result.routes[0].legs[0].arrivalTime).toLowerCase());
assertEquals("1:21 pm", fmt.print(result.routes[0].legs[0].departureTime).toLowerCase());
sc.assertParamValue(TravelMode.TRANSIT.toUrlValue(), "mode");
sc.assertParamValue("483 George St, Sydney NSW 2000, Australia", "origin");
sc.assertParamValue("182 Church St, Parramatta NSW 2150, Australia", "destination");
}
}
示例10: testTorontoToMontrealByBicycleAvoidingHighways
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/**
* Going from Toronto to Montreal by bicycle, avoiding highways.
*
* <p>{@code
* http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&avoid=highways&mode=bicycling}
*/
@Test
public void testTorontoToMontrealByBicycleAvoidingHighways() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
DirectionsApi.newRequest(sc.context)
.origin("Toronto")
.destination("Montreal")
.avoid(DirectionsApi.RouteRestriction.HIGHWAYS)
.mode(TravelMode.BICYCLING)
.await();
sc.assertParamValue("Toronto", "origin");
sc.assertParamValue("Montreal", "destination");
sc.assertParamValue(RouteRestriction.HIGHWAYS.toUrlValue(), "avoid");
sc.assertParamValue(TravelMode.BICYCLING.toUrlValue(), "mode");
}
}
示例11: testBrooklynToQueensByTransit
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/**
* Brooklyn to Queens by public transport.
*
* <p>{@code
* http://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&departure_time=1343641500&mode=transit}
*/
@Test
public void testBrooklynToQueensByTransit() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
DirectionsApi.newRequest(sc.context)
.origin("Brooklyn")
.destination("Queens")
.mode(TravelMode.TRANSIT)
.await();
sc.assertParamValue("Brooklyn", "origin");
sc.assertParamValue("Queens", "destination");
sc.assertParamValue(TravelMode.TRANSIT.toUrlValue(), "mode");
}
}
示例12: testTrafficModel
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/** Tests the {@code traffic_model} and {@code duration_in_traffic} parameters. */
@Test
public void testTrafficModel() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}"); ) {
DirectionsApi.newRequest(sc.context)
.origin("48 Pirrama Road, Pyrmont NSW 2009")
.destination("182 Church St, Parramatta NSW 2150")
.mode(TravelMode.DRIVING)
.departureTime(new DateTime().plus(Duration.standardMinutes(2)))
.trafficModel(TrafficModel.PESSIMISTIC)
.await();
sc.assertParamValue("48 Pirrama Road, Pyrmont NSW 2009", "origin");
sc.assertParamValue("182 Church St, Parramatta NSW 2150", "destination");
sc.assertParamValue(TravelMode.DRIVING.toUrlValue(), "mode");
sc.assertParamValue(TrafficModel.PESSIMISTIC.toUrlValue(), "traffic_model");
}
}
示例13: testTransitWithoutSpecifyingTime
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/** Test transit without arrival or departure times specified. */
@Test
public void testTransitWithoutSpecifyingTime() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
DirectionsApi.newRequest(sc.context)
.origin("Fisherman's Wharf, San Francisco")
.destination("Union Square, San Francisco")
.mode(TravelMode.TRANSIT)
.await();
sc.assertParamValue("Fisherman's Wharf, San Francisco", "origin");
sc.assertParamValue("Union Square, San Francisco", "destination");
sc.assertParamValue(TravelMode.TRANSIT.toUrlValue(), "mode");
}
}
示例14: testTransitParams
import com.google.maps.model.TravelMode; //导入依赖的package包/类
/** Test the extended transit parameters: mode and routing preference. */
@Test
public void testTransitParams() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
DirectionsApi.newRequest(sc.context)
.origin("Fisherman's Wharf, San Francisco")
.destination("Union Square, San Francisco")
.mode(TravelMode.TRANSIT)
.transitMode(TransitMode.BUS, TransitMode.TRAM)
.transitRoutingPreference(TransitRoutingPreference.LESS_WALKING)
.await();
sc.assertParamValue("Fisherman's Wharf, San Francisco", "origin");
sc.assertParamValue("Union Square, San Francisco", "destination");
sc.assertParamValue(TravelMode.TRANSIT.toUrlValue(), "mode");
sc.assertParamValue(
TransitMode.BUS.toUrlValue() + "|" + TransitMode.TRAM.toUrlValue(), "transit_mode");
sc.assertParamValue(
TransitRoutingPreference.LESS_WALKING.toUrlValue(), "transit_routing_preference");
}
}
示例15: testTravelModeWalking
import com.google.maps.model.TravelMode; //导入依赖的package包/类
@Test
public void testTravelModeWalking() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}"); ) {
DirectionsResult result =
DirectionsApi.newRequest(sc.context)
.mode(TravelMode.WALKING)
.origin("483 George St, Sydney NSW 2000, Australia")
.destination("182 Church St, Parramatta NSW 2150, Australia")
.await();
assertNotNull(result.routes);
assertNotNull(result.routes[0]);
sc.assertParamValue(TravelMode.WALKING.toUrlValue(), "mode");
sc.assertParamValue("483 George St, Sydney NSW 2000, Australia", "origin");
sc.assertParamValue("182 Church St, Parramatta NSW 2150, Australia", "destination");
}
}