【问题标题】:how to draw an arc line on google map?如何在谷歌地图上画弧线?
【发布时间】:2018-04-16 04:05:48
【问题描述】:

嗨,有人可以帮我画一条弧线,就像优步在谷歌地图上所做的那样吗? 我需要绘制一个质量不会因放大和移动地图而降低的 ling 不会导致滞后... 我看过这个库

https://github.com/amalChandran/trail-android
我需要像 uber 一样的平滑线 任何帮助表示赞赏... 喜欢这张照片

【问题讨论】:

  • 使用那个库有什么错误?
  • @VishvaDave 在放大和快速移动地图时出现质量问题。
  • 还有其他想法吗?

标签: android google-maps


【解决方案1】:

compile 'com.google.maps.android:android-maps-utils:0.5'//依赖,SphericalUtil有一些函数可以计算两点之间的航向,距离和偏移量,可能对你有帮助!

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private LatLng sydney1;
private LatLng sydney2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.getUiSettings().setZoomControlsEnabled(true);

    // Add a marker in Sydney and move the camera
    sydney1 = new LatLng(-33.904438,151.249852);
    sydney2 = new LatLng(-33.905823,151.252422);

    mMap.addMarker(new MarkerOptions().position(sydney1)
            .draggable(false).visible(true).title("Marker in Sydney 1"));
    mMap.addMarker(new MarkerOptions().position(sydney2)
            .draggable(false).visible(true).title("Marker in Sydney 2"));

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney1, 16F));

    this.showCurvedPolyline(sydney1,sydney2, 0.5);
}

private void showCurvedPolyline (LatLng p1, LatLng p2, double k) {
    //Calculate distance and heading between two points
    double d = SphericalUtil.computeDistanceBetween(p1,p2);
    double h = SphericalUtil.computeHeading(p1, p2);

    //Midpoint position
    LatLng p = SphericalUtil.computeOffset(p1, d*0.5, h);

    //Apply some mathematics to calculate position of the circle center
    double x = (1-k*k)*d*0.5/(2*k);
    double r = (1+k*k)*d*0.5/(2*k);

    LatLng c = SphericalUtil.computeOffset(p, x, h + 90.0);

    //Polyline options
    PolylineOptions options = new PolylineOptions();

    //Calculate heading between circle center and two points
    double h1 = SphericalUtil.computeHeading(c, p1);
    double h2 = SphericalUtil.computeHeading(c, p2);

    //Calculate positions of points on circle border and add them to polyline options
    int numpoints = 100;
    double step = (h2 -h1) / numpoints;

    for (int i=0; i < numpoints; i++) {
        LatLng pi = SphericalUtil.computeOffset(c, r, h1 + i * step);
        options.add(pi);
    }

    //Draw polyline
    mMap.addPolyline(options.width(10).color(Color.BLACK).geodesic(false));
}

}

结果

【讨论】:

猜你喜欢
  • 2014-09-17
  • 1970-01-01
  • 2018-04-06
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
  • 2011-10-12
  • 2017-12-06
  • 2011-01-11
相关资源
最近更新 更多