Android谷歌地图两点之间的路线

时间:2017-02-27 09:43:56

标签: java android google-maps

我试图在2点之间显示路线,但看起来它比我更强硬,虽然有足够的帖子就可以了。

enter image description here

这是我的代码

public class MainActivity extends FragmentActivity implements OnMapReadyCallback
{

    private GoogleMap mMap;



    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);



    }

@Override
    public void onMapReady(GoogleMap googleMap)
    {
        mMap = googleMap;
        Context context;
        LatLng Current = new LatLng(55.0567842,-1.599155200000041);
        LatLng Target = new LatLng(55.0239304,-1.5453314000000091);

        LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
        boundsBuilder.include(Current);
        boundsBuilder.include(Target);

        LatLngBounds bounds = boundsBuilder.build();
        mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 3));

        PolylineOptions polyOptions = new PolylineOptions();
        polyOptions.color(ContextCompat.getColor(context, R.color.colorPrimary));
        polyOptions.width(10);
        polyOptions.add(Current, Target);




    }

非常感谢任何帮助。

0 个答案:

没有答案