将相机设置在两点的CENTER上

时间:2015-01-24 09:21:49

标签: android eclipse dictionary camera marker

美好的一天每个人!,我是创建Android应用程序的新手,我经常在编码方面遇到困难。我目前正在创建一个关于提供路线的Android应用程序。我已经有了两点和路线我的问题是如何将相机设置在这些点的中心?

这是我的代码:

protected void setMarker(String locality, String country, double lat, double lng) {

        // Already two locations                
        if (markerPoints.size() > 1) {
            markerPoints.clear();
            map.clear();
        }

        // Adding new item to the ArrayList
        markerPoints.add(new LatLng(lat, lng));

        // Creating MarkerOptions
        MarkerOptions options = new MarkerOptions();

        // Setting the position of the marker
        options.position(new LatLng(lat, lng));

        /**
         * For the start location, the color of marker is GREEN and
         * for the end location, the color of marker is RED.
         */
        if (markerPoints.size() == 1) {
            options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
                    .title(locality);
            options.snippet(country);

        } else if (markerPoints.size() == 2) {
            options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
                    .title(locality);
            options.snippet(country);
        }


        // Add new marker to the Google Map Android API V2
        map.addMarker(options);

        // Checks, whether start and end locations are captured
        if (markerPoints.size() >= 2) {
            LatLng origin = markerPoints.get(0);
            LatLng dest = markerPoints.get(1);

            // Getting URL to the Google Directions API
            String url = getDirectionsUrl(origin, dest);

            DownloadTask downloadTask = new DownloadTask();

            // Start downloading json data from Google Directions API
            downloadTask.execute(url);

        }
    }

1 个答案:

答案 0 :(得分:0)

以下是一些查找两个(或更多)点之间中点的方法:http://www.geomidpoint.com/calculation.html