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


Java Position类代码示例

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


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

示例1: getLocationMap

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
public static String getLocationMap(Position position, boolean isSmall) {
    StaticMarkerAnnotation marker = new StaticMarkerAnnotation.Builder()
            .setName(com.mapbox.services.Constants.PIN_LARGE)
            .setPosition(position)
            .setColor(COLOR_RED)
            .build();
    MapboxStaticImage client = new MapboxStaticImage.Builder()
            .setAccessToken(Constants.MAPBOX_ACCESS_TOKEN)
            .setWidth(isSmall ? smallWidth : largeWidth)
            .setHeight(isSmall ? smallHeight : largeHeight)
            .setStyleId(com.mapbox.services.Constants.MAPBOX_STYLE_STREETS)
            .setPosition(position)
            .setStaticMarkerAnnotations(marker)
            .setZoom(15)
            .build();
    return client.getUrl().toString();
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:18,代码来源:ImageComponent.java

示例2: getCoordinatesFromAddress

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
public static Position getCoordinatesFromAddress(String address, Position proximity) {
    try {
        log.info(String.format("Looking for '%s'.", address));
        MapboxGeocoding.Builder builder = new MapboxGeocoding.Builder()
                .setAccessToken(Constants.MAPBOX_ACCESS_TOKEN)
                .setMode(GeocodingCriteria.MODE_PLACES)
                .setCountry("US")
                .setLimit(1)
                .setLocation(address);

        if (proximity != null) {
            // Add support for bias
            builder.setProximity(proximity);
        }

        Response<GeocodingResponse> response = builder.build().executeCall();
        double[] coordinates = response.body().getFeatures().get(0).getCenter();
        log.info(String.format("Found at '%f,%f'.", coordinates[0], coordinates[1]));
        return Position.fromCoordinates(coordinates);
    } catch (Exception e) {
        log.error("Geocoding failed.", e);
    }

    return null;
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:26,代码来源:AddressUtils.java

示例3: addNoiseToRoute

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
/**
 * Emulate a noisy route using this method. Note that some points might not be noisy if the random value produced
 * equals 0.
 *
 * @since 2.2.0
 */
private void addNoiseToRoute(double distance) {

  // End point will always match the given route (no noise will be added)
  for (int i = 0; i < positions.size() - 1; i++) {

    double bearing = TurfMeasurement.bearing(positions.get(i), positions.get(i + 1));
    Random random = new Random();
    bearing = random.nextInt(15 - -15) + bearing;

    Position position = TurfMeasurement.destination(
      positions.get(i), distance, bearing, TurfConstants.UNIT_KILOMETERS
    );
    positions.set(i, position);
  }
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:22,代码来源:MockLocationEngine.java

示例4: mockLocation

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
/**
 * Here we build the new mock {@link Location} object and fill in as much information we can calculate.
 *
 * @param position taken from the positions list, converts this to a {@link Location}.
 * @return a {@link Location} object with as much information filled in as possible.
 * @since 2.2.0
 */
private Location mockLocation(Position position) {
  lastLocation = new Location(MockLocationEngine.class.getName());
  lastLocation.setLatitude(position.getLatitude());
  lastLocation.setLongitude(position.getLongitude());

  // Need to convert speed to meters/second as specified in Android's Location object documentation.
  float speedInMeterPerSec = (float) (((speed * 1.609344) * 1000) / (60 * 60));
  lastLocation.setSpeed(speedInMeterPerSec);

  if (positions.size() >= 2) {
    double bearing = TurfMeasurement.bearing(position, positions.get(1));
    lastLocation.setBearing((float) bearing);
  }

  lastLocation.setAccuracy(3f);
  lastLocation.setTime(SystemClock.elapsedRealtime());

  return lastLocation;
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:27,代码来源:MockLocationEngine.java

示例5: drawRoute

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
private void drawRoute(DirectionsRoute route) {
  // Convert LineString coordinates into LatLng[]
  LineString lineString = LineString.fromPolyline(route.getGeometry(), PRECISION_6);
  List<Position> coordinates = lineString.getCoordinates();
  LatLng[] points = new LatLng[coordinates.size()];
  for (int i = 0; i < coordinates.size(); i++) {
    points[i] = new LatLng(
      coordinates.get(i).getLatitude(),
      coordinates.get(i).getLongitude());
  }

  // Draw Points on MapView
  map.addPolyline(new PolylineOptions()
    .add(points)
    .color(Color.parseColor("#009688"))
    .width(5));
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:18,代码来源:DirectionsActivity.java

示例6: drawSimplify

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
private void drawSimplify(List<Position> points) {

    Position[] before = new Position[points.size()];
    for (int i = 0; i < points.size(); i++) {
      before[i] = points.get(i);
    }

    Position[] after = PolylineUtils.simplify(before, 0.001);

    LatLng[] result = new LatLng[after.length];
    for (int i = 0; i < after.length; i++) {
      result[i] = new LatLng(after[i].getLatitude(), after[i].getLongitude());
    }

    map.addPolyline(new PolylineOptions()
      .add(result)
      .color(Color.parseColor("#3bb2d0"))
      .width(4));
  }
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:20,代码来源:SimplifyPolylineActivity.java

示例7: doInBackground

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
@Override
protected List<Position> doInBackground(Void... voids) {

  List<Position> points = new ArrayList<>();

  try {
    // Load GeoJSON file
    InputStream inputStream = getAssets().open("trace.geojson");
    BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
    StringBuilder sb = new StringBuilder();
    int cp;
    while ((cp = rd.read()) != -1) {
      sb.append((char) cp);
    }

    inputStream.close();
    FeatureCollection featureCollection = FeatureCollection.fromJson(sb.toString());
    LineString lineString = (LineString) featureCollection.getFeatures().get(0).getGeometry();
    points = lineString.getCoordinates();
  } catch (Exception exception) {
    Log.e(TAG, "Exception Loading GeoJSON: " + exception.toString());
  }

  return points;
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:26,代码来源:MapMatchingActivity.java

示例8: calculateLinePoints

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static List<com.mapbox.geojson.Point> calculateLinePoints(
  FeatureCollection featureCollection) {
  List<com.mapbox.geojson.Point> linePoints = new ArrayList<>();
  for (Feature feature : featureCollection.getFeatures()) {
    List<Position> positions = (List<Position>) feature.getGeometry().getCoordinates();
    for (Position pos : positions) {
      linePoints.add(com.mapbox.geojson
        .Point.fromLngLat(pos.getLongitude(), pos.getLatitude()));
    }
  }
  return linePoints;
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:14,代码来源:NavigationMapRoute.java

示例9: getPositionFromKey

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
private Position getPositionFromKey(String key) {
    try {
        S3Object object = s3.getObject(new GetObjectRequest(BUCKET_NAME, key));
        BufferedReader reader = new BufferedReader(new InputStreamReader(object.getObjectContent()));
        StringBuilder sb = new StringBuilder();
        while (true) {
            String line = reader.readLine();
            if (line == null) break;
            sb.append(line);
        }
        return new Gson().fromJson(sb.toString(), Position.class);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:16,代码来源:StorageManager.java

示例10: getRouteMap

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
public static String getRouteMap(Position origin, Position destination, String geometry, boolean isSmall) {
    StaticMarkerAnnotation markerOrigin = new StaticMarkerAnnotation.Builder()
            .setName(com.mapbox.services.Constants.PIN_LARGE)
            .setPosition(origin)
            .setColor(COLOR_GREEN)
            .build();
    StaticMarkerAnnotation markerDestination = new StaticMarkerAnnotation.Builder()
            .setName(com.mapbox.services.Constants.PIN_LARGE)
            .setPosition(destination)
            .setColor(COLOR_RED)
            .build();
    StaticPolylineAnnotation route = new StaticPolylineAnnotation.Builder()
            .setPolyline(geometry)
            .setStrokeColor(COLOR_BLUE)
            .setStrokeOpacity(1)
            .setStrokeWidth(5)
            .build();
    MapboxStaticImage client = new MapboxStaticImage.Builder()
            .setAccessToken(Constants.MAPBOX_ACCESS_TOKEN)
            .setWidth(isSmall ? smallWidth : largeWidth)
            .setHeight(isSmall ? smallHeight : largeHeight)
            .setStyleId(com.mapbox.services.Constants.MAPBOX_STYLE_TRAFFIC_DAY)
            .setAuto(true)
            .setStaticMarkerAnnotations(markerOrigin, markerDestination)
            .setStaticPolylineAnnotations(route)
            .setZoom(15)
            .build();
    return client.getUrl().toString();
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:30,代码来源:ImageComponent.java

示例11: getHomeAddressResponse

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
public SpeechletResponse getHomeAddressResponse(Slot postalAddress, Slot city) {
    String speechText;
    String cardText;
    Image image = null;

    String address = AddressUtils.getAddressFromSlot(postalAddress, city, null);

    try {
        Position position = AddressUtils.getCoordinatesFromAddress(address, null);
        storageManager.setHomeAddress(position);
        speechText = "Thank you, home address set.";
        cardText = String.format(Locale.US, "Thank you, home address set: %s", address);
        image = new Image();
        image.setSmallImageUrl(ImageComponent.getLocationMap(position, true));
        image.setLargeImageUrl(ImageComponent.getLocationMap(position, false));
    } catch (Exception e) {
        speechText = "Sorry, I couldn't find that address.";
        cardText = String.format(Locale.US, "Sorry, I couldn't find that address: %s", address);
    }

    // Create a standard card content
    StandardCard card = new StandardCard();
    card.setTitle(CARD_TITLE);
    card.setText(cardText);

    // Card image
    if (image != null) {
        card.setImage(image);
    }

    // Create the plain text output
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);

    return SpeechletResponse.newTellResponse(speech, card);
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:37,代码来源:IntentManager.java

示例12: getOfficeAddressResponse

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
public SpeechletResponse getOfficeAddressResponse(Slot postalAddress, Slot city) {
    String speechText;
    String cardText;
    Image image = null;

    String address = AddressUtils.getAddressFromSlot(postalAddress, city, null);

    try {
        Position proximity = storageManager.getHomeAddress();
        Position position = AddressUtils.getCoordinatesFromAddress(address, proximity);
        storageManager.setOfficeAddress(position);
        cardText = String.format(Locale.US, "Thank you, office address set: %s", address);
        speechText = "Thank you, office address set.";
        image = new Image();
        image.setSmallImageUrl(ImageComponent.getLocationMap(position, true));
        image.setLargeImageUrl(ImageComponent.getLocationMap(position, false));
    } catch (Exception e) {
        cardText = String.format(Locale.US, "Sorry, I couldn't find that address: %s", address);
        speechText = "Sorry, I couldn't find that address.";
    }

    // Create a standard card content
    StandardCard card = new StandardCard();
    card.setTitle(CARD_TITLE);
    card.setText(cardText);

    // Card image
    if (image != null) {
        card.setImage(image);
    }

    // Create the plain text output
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);

    return SpeechletResponse.newTellResponse(speech, card);
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:38,代码来源:IntentManager.java

示例13: getRouteMapIsNotEmpty

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
@Test
public void getRouteMapIsNotEmpty() {
    // From https://www.mapbox.com/api-playground/#/directions
    String geometry = "}[email protected]?xC}[email protected][email protected]@FItAaAhCaAH?ZqD`[email protected]@[email protected]@[email protected]";

    Position whiteHouse = Position.fromCoordinates(-77.0365, 38.8977);
    Position dupontCircle = Position.fromCoordinates(-77.04341, 38.90962);
    assertTrue(ImageComponent.getRouteMap(whiteHouse, dupontCircle, geometry, true).startsWith(BASE_URL));
    assertTrue(ImageComponent.getRouteMap(whiteHouse, dupontCircle, geometry, false).startsWith(BASE_URL));
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:11,代码来源:ImageComponentTest.java

示例14: onConnected

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
@SuppressWarnings({"MissingPermission"})
@Override
public void onConnected() {
  locationEngine.requestLocationUpdates();

  if (locationEngine.getLastLocation() != null) {
    Location lastLocation = locationEngine.getLastLocation();
    currentUserPosition = Position.fromLngLat(lastLocation.getLongitude(), lastLocation.getLatitude());
    checkIntentExtras();
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-hud-demo,代码行数:12,代码来源:DisplayActivity.java

示例15: checkIntentExtras

import com.mapbox.services.commons.models.Position; //导入依赖的package包/类
private void checkIntentExtras() {
  if (getIntent().hasExtra(PLACE_LOCATION_EXTRA)) {
    Location placeLocation = getIntent().getParcelableExtra(PLACE_LOCATION_EXTRA);
    Position destination = Position.fromLngLat(placeLocation.getLongitude(), placeLocation.getLatitude());

    if (currentUserPosition != null) {
      navigation.getRoute(currentUserPosition, destination, this);
    } else {
      Toast.makeText(this, "Current Location is null", Toast.LENGTH_LONG).show();
    }
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-hud-demo,代码行数:13,代码来源:DisplayActivity.java


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