本文整理汇总了Java中com.google.android.gms.maps.model.Polyline类的典型用法代码示例。如果您正苦于以下问题:Java Polyline类的具体用法?Java Polyline怎么用?Java Polyline使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Polyline类属于com.google.android.gms.maps.model包,在下文中一共展示了Polyline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zoomToPolyline
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
public static void zoomToPolyline(GoogleMap map, Polyline p) {
if (p == null || p.getPoints().isEmpty())
return;
LatLngBounds.Builder builder = LatLngBounds.builder();
for (LatLng latLng : p.getPoints()) {
builder.include(latLng);
}
final LatLngBounds bounds = builder.build();
try{
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 150));
} catch (Exception e){
e.printStackTrace();
}
}
示例2: getClickListener
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
private View.OnClickListener getClickListener(final GpxTreeItem value) {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (value.type) {
case ITEM_TYPE_TRACK:
Polyline polyline = value.polylines[0];
MapUtils.zoomToPolyline(manager.getCurrentMap(), polyline);
value.polylines[0].setColor(CHOSEN_TRACK_COLOR);
value.polylines[0].setZIndex(ZINDEX_POLYLINE_CHOSEN);
if (lastClickedPolyline != null) {
lastClickedPolyline.setColor(DEFAULT_TRACK_COLOR);
lastClickedPolyline.setZIndex(ZINDEX_POLYLINE);
}
lastClickedPolyline = polyline;
break;
case ITEM_TYPE_WAYPOINT:
MapUtils.zoomToMarker(manager.getCurrentMap(),
value.marker);
break;
}
}
};
}
示例3: addPolylineToMapAsMarkers
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/**
* Add a Polyline to the map as markers
*
* @param map
* @param polylineOptions
* @param polylineMarkerOptions
* @param globalPolylineOptions
* @return
*/
public PolylineMarkers addPolylineToMapAsMarkers(GoogleMap map,
PolylineOptions polylineOptions,
MarkerOptions polylineMarkerOptions,
PolylineOptions globalPolylineOptions) {
PolylineMarkers polylineMarkers = new PolylineMarkers(this);
if (globalPolylineOptions != null) {
polylineOptions.color(globalPolylineOptions.getColor());
polylineOptions.geodesic(globalPolylineOptions.isGeodesic());
}
Polyline polyline = addPolylineToMap(map, polylineOptions);
polylineMarkers.setPolyline(polyline);
List<Marker> markers = addPointsToMapAsMarkers(map,
polylineOptions.getPoints(), polylineMarkerOptions, false);
polylineMarkers.setMarkers(markers);
return polylineMarkers;
}
示例4: addInterval
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
private void addInterval(Context context, GoogleMap map, ProcessedDataModel item, boolean addCache) {
double[] coordsStart = item.getCoordsStart();
double[] coordsEnd = item.getCoordsStart();
if (coordsStart == null || coordsEnd == null
|| coordsStart.length < 2 || coordsEnd.length < 2) {
return;
}
LatLng startLine = new LatLng(item.getCoordsStart()[0], item.getCoordsStart()[1]);
LatLng endLine = new LatLng(item.getCoordsEnd()[0], item.getCoordsEnd()[1]);
Polyline line = map.addPolyline(new PolylineOptions()
.add(startLine, endLine)
.geodesic(true)
.width(context.getResources().getDimension(R.dimen.map_polyline_width))
.color(getIriColor(context, item.getCategory())));
if (addCache && linesCache != null) {
linesCache.put(line, item);
}
}
示例5: drawGraph
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/**
* @param graph to use in drawing polyOptions on the graph.
*/
@Override
public void drawGraph(Graph graph) {
PolylineOptions graphOptions = new PolylineOptions();
List<Location> locationList = graph.getLocations();
for (Location location: locationList){
LatLng currentPosition = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions options = new MarkerOptions();
options.position(currentPosition)
.icon(BitmapDescriptorFactory.defaultMarker())
.title("Position")
.snippet("Some Position");
googleMap.addMarker(options);
graphOptions.add(currentPosition);
}
Polyline graphPolygon = googleMap.addPolyline(graphOptions);
graphPolygon.setGeodesic(true);
graphPolygon.setColor(Color.DKGRAY);
graphPolygon.setWidth(20);
}
示例6: drawRoute
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/**
* Helper function used to draw routes on the map given 2 locations
*
* @param mMap
* @param decodedPolyLine
* @param polylineArrayList
* @return
*/
public int drawRoute(GoogleMap mMap, List<LatLng> decodedPolyLine, ArrayList<Polyline> polylineArrayList) {
int routeDistance = 0;
for (int i = 0; i < (decodedPolyLine.size() - 1); i++) {
LatLng point1 = decodedPolyLine.get(i);
LatLng point2 = decodedPolyLine.get(i + 1);
Location location1 = new Location("1");
location1.setLatitude(point1.latitude);
location1.setLongitude(point1.longitude);
Location location2 = new Location("2");
location2.setLatitude(point2.latitude);
location2.setLongitude(point2.longitude);
routeDistance += location1.distanceTo(location2);
polylineArrayList.add(mMap.addPolyline(new PolylineOptions()
.add(point1, point2)
.width(5)
.color(Color.RED)));
}
return routeDistance;
}
示例7: setTracksVisible
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
public void setTracksVisible(boolean visible) {
for (Map.Entry<String, Polyline> entry :
mRoutesMap.entrySet()) {
Polyline route = entry.getValue();
if (route != null) {
Marker start = mRouteStartMarksMap.get(route);
if (start != null) {
start.setVisible(visible);
}
Marker end = mRouteEndMarksMap.get(route);
if (end != null) {
end.setVisible(visible);
}
route.setVisible(visible);
}
}
}
示例8: drawPath
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
private Polyline drawPath(List<LatLong> latLongs, int color, float zIndex, Polyline polyline) {
if (googleMap != null && latLongs != null && !latLongs.isEmpty()) {
PolylineOptions polyLineOptions = new PolylineOptions();
polyLineOptions.width(getResources().getDimension(R.dimen._2dp));
polyLineOptions.color(color);
polyLineOptions.zIndex(zIndex);
for (LatLong latLong : latLongs) {
polyLineOptions.add(new LatLng(latLong.latitude(), latLong.longitude()));
}
if (polyline != null) polyline.remove();
return googleMap.addPolyline(polyLineOptions);
}
return null;
}
示例9: remove
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/**
* Remove the polyline
* @param args
* @param callbackContext
* @throws JSONException
*/
@SuppressWarnings("unused")
private void remove(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
String id = args.getString(1);
Polyline polyline = this.getPolyline(id);
if (polyline == null) {
this.sendNoResult(callbackContext);
return;
}
this.objects.remove(id);
id = "polyline_bounds_" + polyline.getId();
this.objects.remove(id);
polyline.remove();
this.sendNoResult(callbackContext);
}
示例10: setPoints
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/**
* Set points
* @param args
* @param callbackContext
* @throws JSONException
*/
@SuppressWarnings("unused")
private void setPoints(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
String id = args.getString(1);
Polyline polyline = this.getPolyline(id);
JSONArray points = args.getJSONArray(2);
List<LatLng> path = PluginUtil.JSONArray2LatLngList(points);
polyline.setPoints(path);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (int i = 0; i < path.size(); i++) {
builder.include(path.get(i));
}
this.objects.put("polyline_bounds_" + polyline.getId(), builder.build());
this.sendNoResult(callbackContext);
}
示例11: call
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
@Override public void call(final Subscriber<? super Polyline> subscriber) {
GoogleMap.OnPolylineClickListener listener = new GoogleMap.OnPolylineClickListener() {
@Override public void onPolylineClick(Polyline polyline) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(polyline);
}
}
};
googleMap.setOnPolylineClickListener(listener);
subscriber.add(Subscriptions.create(new Action0() {
@Override public void call() {
googleMap.setOnPolylineClickListener(null);
}
}));
}
示例12: onRoutingSuccess
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
@Override
public void onRoutingSuccess(ArrayList<Route> route, int j) {
if (polylines.size() > 0) {
for (Polyline poly : polylines) {
poly.remove();
}
}
polylines = new ArrayList<>();
//add route(s) to the map.
for (int i = 0; i < route.size(); i++) {
//In case of more than 5 alternative routes
int colorIndex = i % COLORS.length;
PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(getResources().getColor(COLORS[colorIndex]));
polyOptions.width(10 + i * 3);
polyOptions.addAll(route.get(i).getPoints());
Polyline polyline = mMap.addPolyline(polyOptions);
polylines.add(polyline);
}
}
示例13: update
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/**
* Updates the track, start and end markers, and waypoints.
*
* @param googleMap the google map
* @param paths the paths
* @param tripStatistics the trip statistics
* @param reload true to reload all points
* @return true if has the start marker
*/
public boolean update(GoogleMap googleMap, ArrayList<Polyline> paths,
TripStatistics tripStatistics, boolean reload) {
synchronized (locations) {
boolean hasStartMarker = false;
// Merge pendingLocations with locations
int newLocations = pendingLocations.drainTo(locations);
// Call updateState first because we want to update its state each time
// (for dynamic coloring)
if (trackPath.updateState(tripStatistics) || reload) {
googleMap.clear();
paths.clear();
trackPath.updatePath(googleMap, paths, 0, locations);
hasStartMarker = updateStartAndEndMarkers(googleMap);
updateWaypoints(googleMap);
} else {
if (newLocations != 0) {
int numLocations = locations.size();
trackPath.updatePath(googleMap, paths, numLocations - newLocations, locations);
}
}
return hasStartMarker;
}
}
示例14: addPath
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/**
* Add a path.
*
* @param googleMap the google map
* @param paths the existing paths
* @param points the path points
* @param color the path color
* @param append true to append to the last path
*/
public static void addPath(GoogleMap googleMap, ArrayList<Polyline> paths,
ArrayList<LatLng> points, int color, boolean append) {
if (points.size() == 0) {
return;
}
if (append && paths.size() != 0) {
Polyline lastPolyline = paths.get(paths.size() - 1);
ArrayList<LatLng> pathPoints = new ArrayList<LatLng>();
pathPoints.addAll(lastPolyline.getPoints());
pathPoints.addAll(points);
lastPolyline.setPoints(pathPoints);
} else {
PolylineOptions polylineOptions = new PolylineOptions().addAll(points).width(5).color(color);
Polyline polyline = googleMap.addPolyline(polylineOptions);
paths.add(polyline);
}
points.clear();
}
示例15: drawRoute
import com.google.android.gms.maps.model.Polyline; //导入依赖的package包/类
/** draw the route on the map, if there is a created route,
* It will be removed to create another.
* */
private void drawRoute(List<LatLng> latlngList){
if(latlngList != null){
if(polylineList != null){
for(Polyline polyline : polylineList){
polyline.remove();
}
}
polylineList = new ArrayList<Polyline>();
for (int i = 0; i < latlngList.size() - 1; i++) {
LatLng src = latlngList.get(i);
LatLng dest = latlngList.get(i + 1);
Polyline polyLine = mMap.addPolyline(
new PolylineOptions()
.add(new LatLng(src.latitude, src.longitude), new LatLng(dest.latitude,dest.longitude))
.width(4)
.color(Color.BLUE)
.geodesic(true));
polylineList.add(polyLine);
}
}
}