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


Java LatLng类代码示例

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


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

示例1: buildCameraPositionFromLocation

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
/**
 * Creates a camera position based on the given location.
 * <p>
 * From the {@link Location}, a target position is created.
 * Then using a preset tilt and zoom (based on screen orientation), a {@link CameraPosition} is built.
 *
 * @param location used to build the camera position
 * @return camera position to be animated to
 */
@NonNull
private CameraPosition buildCameraPositionFromLocation(Location location) {
  Point targetPoint = TurfMeasurement.destination(
    Point.fromLngLat(location.getLongitude(), location.getLatitude()),
    targetDistance, location.getBearing(), TurfConstants.UNIT_METERS
  );

  LatLng target = new LatLng(
    targetPoint.latitude(),
    targetPoint.longitude()
  );

  return new CameraPosition.Builder()
    .tilt(CAMERA_TILT)
    .zoom(CAMERA_ZOOM)
    .target(target)
    .bearing(location.getBearing())
    .build();
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:29,代码来源:NavigationCamera.java

示例2: drawRoute

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
private void drawRoute(DirectionsRoute route) {
  List<LatLng> points = new ArrayList<>();
  List<Point> coords = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6).coordinates();

  for (Point point : coords) {
    points.add(new LatLng(point.latitude(), point.longitude()));
  }

  if (!points.isEmpty()) {

    if (polyline != null) {
      mapboxMap.removePolyline(polyline);
    }

    // Draw polyline on map
    polyline = mapboxMap.addPolyline(new PolylineOptions()
      .addAll(points)
      .color(Color.parseColor("#4264fb"))
      .width(5));
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:22,代码来源:RerouteActivity.java

示例3: boundCameraToRoute

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
public void boundCameraToRoute() {
  if (route != null) {
    List<Point> routeCoords = LineString.fromPolyline(route.geometry(),
      Constants.PRECISION_6).coordinates();
    List<LatLng> bboxPoints = new ArrayList<>();
    for (Point point : routeCoords) {
      bboxPoints.add(new LatLng(point.latitude(), point.longitude()));
    }
    if (bboxPoints.size() > 1) {
      try {
        LatLngBounds bounds = new LatLngBounds.Builder().includes(bboxPoints).build();
        animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, new int[] {50, 500, 50, 335});
      } catch (InvalidLatLngBoundsException exception) {
        Toast.makeText(this, "Valid route not found.", Toast.LENGTH_SHORT).show();
      }
    }
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:19,代码来源:NavigationViewActivity.java

示例4: onMapLongClick

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
@Override
public void onMapLongClick(@NonNull LatLng point) {
  if (originMarker == null) {
    originMarker = mapboxMap.addMarker(new MarkerOptions().position(point));
  } else if (destinationMarker == null) {
    destinationMarker = mapboxMap.addMarker(new MarkerOptions().position(point));
    Point originPoint = Point.fromLngLat(
      originMarker.getPosition().getLongitude(), originMarker.getPosition().getLatitude());
    Point destinationPoint = Point.fromLngLat(
      destinationMarker.getPosition().getLongitude(), destinationMarker.getPosition().getLatitude());
    requestDirectionsRoute(originPoint, destinationPoint);
    mapboxMap.removeMarker(originMarker);
    mapboxMap.removeMarker(destinationMarker);
  } else {
    originMarker = null;
    destinationMarker = null;
    navigationMapRoute.removeRoute();
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:20,代码来源:NavigationMapRouteActivity.java

示例5: updateSurroundingMarkers

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
private void updateSurroundingMarkers() {
    if (mMap != null && mSurroundingPlaces != null && !mSurroundingPlaces.isEmpty() && mSurroundingMarkers == null) {
        mLastIconSize = getResources().getDimensionPixelSize(R.dimen.marker_iconsize_normal);
        Icon circle = Utils.drawableToIcon(getActivity(), R.drawable.ic_marker, mLastIconSize);
        List<MarkerOptions> markers = new ArrayList<>();
        for (Place place : mSurroundingPlaces) {
            if (place.hasLocation()) {
                markers.add(new MarkerOptions()
                        .position(new LatLng(place.getLocation().getLatitude(), place.getLocation().getLongitude()))
                        .icon(circle)
                        .title(place.getName()));
            }
        }
        mSurroundingMarkers = mMap.addMarkers(markers);
        for (int i = 0; i < mSurroundingMarkers.size() && mSurroundingMarkers.size() == mSurroundingPlaces.size(); ++i) {
            mMarkerIdToPlaceId.put(mSurroundingMarkers.get(i).getId(), mSurroundingPlaces.get(i).getId());
        }
    }
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:20,代码来源:MapFragment.java

示例6: updateMainMarker

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
private void updateMainMarker() {
    if (mMap != null && mPlace != null && mPlace.hasLocation()) {
        LatLng placeLocation = new LatLng(mPlace.getLocation().getLatitude(), mPlace.getLocation().getLongitude());
        if (mMainMarker == null) {
            mMainMarker = mMap.addMarker(new MarkerOptions()
                    .position(placeLocation)
                    .title(mPlace.getName()));
        } else {
            mMainMarker.setTitle(mPlace.getName() + "-updated");
            mMainMarker.setPosition(placeLocation);
            mMap.updateMarker(mMainMarker);
        }
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(placeLocation, MapFragment.DEFAULT_ZOOMLEVEL);
        mMap.moveCamera(cameraUpdate);
    }
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:17,代码来源:PlaceFragment.java

示例7: recenterMap

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
public void recenterMap() {
    final Location l = gps.getLocation();

    // This shouldn't normally happen, but does on the Android emulator.
    // It only occurs if recenterMap is called before we receive our first
    // gps ping. We normally receive a ping within a second or two of app
    // launch, but *not* if the emulator only pings on demand.
    if( l == null )
        return;

    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            // We'll maintain zoom level and tilt, just want to change position
            CameraPosition old = mapboxMap.getCameraPosition();
            CameraPosition pos = new CameraPosition.Builder()
                    .target(new LatLng(l.getLatitude(), l.getLongitude()))
                    .zoom(old.zoom)
                    .tilt(old.tilt)
                    .build();
            mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
        }
    });
}
 
开发者ID:DaylightingSociety,项目名称:WhereAreTheEyes,代码行数:25,代码来源:MainActivity.java

示例8: recenterCamera

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
public void recenterCamera(View view) {
    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            Location loc = gps.getLocation();
            if( loc == null )
                return;
            CameraPosition position = new CameraPosition.Builder()
                    .target(new LatLng(loc.getLatitude(), loc.getLongitude()))
                    .zoom(17)
                    .bearing(0)
                    .build();
            mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 3000);
        }
    });
}
 
开发者ID:DaylightingSociety,项目名称:WhereAreTheEyes,代码行数:17,代码来源:MainActivity.java

示例9: parsePin

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
private void parsePin(PinData p, String pinString) {
    try {
        ArrayList<String> data = new ArrayList<String>();
        for( String sec : pinString.split(", ") ) {
            data.add(sec);
            if( data.size() < 3 )
                continue;
            double lat = Double.parseDouble(data.get(0));
            double lon = Double.parseDouble(data.get(1));
            int verifies = Integer.parseInt(data.get(2));
            LatLng pos = new LatLng(lat, lon);

            if( !p.pins.containsKey(pos) ) {
                p.pins.put(pos, verifies);
                //Log.d("GPS", "Parsed pin at: " + pinString);
            }
        }
    } catch(Exception e) {
        Log.d("GPS", "Error parsing a pin: " + e.getMessage());
        Log.d("GPS", "Stack trace: " + e.getStackTrace());
    }
}
 
开发者ID:DaylightingSociety,项目名称:WhereAreTheEyes,代码行数:23,代码来源:DownloadPinsTask.java

示例10: onMyLocationChange

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
@Override
public void onMyLocationChange(@Nullable Location location) {
    LatLng pos = new LatLng(location.getLatitude(), location.getLongitude());
    if (mLine != null) {
        mMap.removePolyline(mLine);
        mMap.animateCamera(CameraUpdateFactory.newLatLng(pos));
    } else {
        //zoom first time
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 15));
    }


    mLine = mMap.addPolyline(new PolylineOptions()
            .add(pos)
            .add(mKaabePos)
            .color(Color.parseColor("#3bb2d0"))
            .width(3));


}
 
开发者ID:metinkale38,项目名称:prayer-times-android,代码行数:21,代码来源:FragMap.java

示例11: loadAll

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
void loadAll() {
    if (mapboxMap.getMyLocation() != null)
        moveCamera(new LatLng(mapboxMap.getMyLocation()));

    Long millisecondsAtRefresh = prefs.getLong(Constants.PREFS_TIMESTAMP_OF_HWSPOTS_DOWNLOAD, 0);
    if (millisecondsAtRefresh > 0) {
        //Check if we still have read permission so that we can read the file containing the downloaded HW spots
        if (!isReadStoragePermissionGranted(this))
            requestReadStoragePermission(this);
        else {
            //Load spots and display them as markers and polylines on the map
            new DrawAnnotations().execute();
        }
    } else {
        showDialogDownloadHWSpots();
    }

    /*MarkerViewOptions m=new MarkerViewOptions();
    m.position(new LatLng(-19.9855600, -43.8466700));
    MarkerViewOptions m2=new MarkerViewOptions();
    m2.position(new LatLng( -19.7884002,-43.9402344));

    mapboxMap.addMarker(m);
    mapboxMap.addMarker(m2);*/
}
 
开发者ID:Hitchwiki,项目名称:MyHitchhikingSpots-for-Android,代码行数:26,代码来源:HitchwikiMapViewActivity.java

示例12: ExtendedMarkerViewOptions

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
private ExtendedMarkerViewOptions(Parcel in) {
    marker = new ExtendedMarkerView(this, "", Constants.SPOT_TYPE_UNKNOWN);
    position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
    snippet(in.readString());
    title(in.readString());
    flat(in.readByte() != 0);
    anchor(in.readFloat(), in.readFloat());
    infoWindowAnchor(in.readFloat(), in.readFloat());
    rotation(in.readFloat());
    visible(in.readByte() != 0);
    alpha(in.readFloat());
    if (in.readByte() != 0) {
        // this means we have an icon
        String iconId = in.readString();
        Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
        Icon icon = IconFactory.recreate(iconId, iconBitmap);

        icon(icon);
    }

    tag(in.readString());
    spotType(in.readInt());
}
 
开发者ID:Hitchwiki,项目名称:MyHitchhikingSpots-for-Android,代码行数:24,代码来源:ExtendedMarkerViewOptions.java

示例13: onLocationChanged

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
@Override
public void onLocationChanged(Location location) {
    // Store the new location
    mCurrentLocation = location;

    Log.i(this.getClass().getSimpleName(), "Latitude is: " + String.valueOf(mCurrentLocation.getLatitude()));
    Log.i(this.getClass().getSimpleName(), "Longitude is: " + String.valueOf(mCurrentLocation.getLongitude()));

    if (mCurrentLocation != null) {
        // Move the map camera to where the user location is
        mMap.setCameraPosition(new CameraPosition.Builder()
                .target(new LatLng(location))
                .build());

        // TODO update current location layer on map

    }

    // TODO do this on a separate thread or updating of location is blocked
    String queryGeometry = buildQueryGeometry(mCurrentLocation);
    queryOccurrence(queryGeometry);

}
 
开发者ID:jtklein,项目名称:2016GBIFchallenge,代码行数:24,代码来源:SgActivityMap.java

示例14: PolygonGeometry

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
public PolygonGeometry(MapView mv, Builder builder) {
    this.mapView = mv;
    this.builder = builder;
    this.latLngs = new ArrayList<LatLng>();
    this.outerRingStroke = new PathOverlay(this.lineColor, this.strokeWidth);
    this.outerRingStroke.getPaint().setStyle(Paint.Style.STROKE);
    this.outerRingStroke.getPaint().setAlpha(100);
    this.outerRingStroke.getPaint().setStrokeWidth(3);

    this.outerRingFill = new PathOverlay(this.lineColor, 0);
    this.outerRingFill.getPaint().setStyle(Paint.Style.FILL);
    this.outerRingFill.getPaint().setAlpha(50);

    // Prevent glitching when panning & zooming map (see: https://github.com/mapbox/mapbox-android-sdk/issues/461).
    this.outerRingStroke.setOptimizePath(false);
    this.outerRingFill.setOptimizePath(false);

    this.mapView.getOverlays().add(this.outerRingStroke);
    this.mapView.getOverlays().add(this.outerRingFill);
}
 
开发者ID:affinitybridge,项目名称:cordova-mapbox-android-sdk,代码行数:21,代码来源:PolygonGeometry.java

示例15: isLocationInside

import com.mapbox.mapboxsdk.geometry.LatLng; //导入依赖的package包/类
public static boolean isLocationInside(LatLng point, ArrayList<? extends LatLng> positions) {
    boolean result = false;
    LatLng p1 = positions.get(0);
    for (int i = 1; i < positions.size(); i++) {
        LatLng p2 = positions.get(i);

        if (((p2.getLatitude() <= point.getLatitude()
                && point.getLatitude() < p1.getLatitude())
                || (p1.getLatitude() <= point.getLatitude()
                && point.getLatitude() < p2.getLatitude()))
                && (point.getLongitude() < (p1.getLongitude() - p2.getLongitude())
                * (point.getLatitude() - p2.getLatitude())
                / (p1.getLatitude() - p2.getLatitude()) + p2.getLongitude())) {
            result = !result;
        }
        p1 = p2;
    }
    return result;
}
 
开发者ID:platypusllc,项目名称:tablet,代码行数:20,代码来源:PolyArea.java


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