android google directions

    private void startDirections(Data data) {
        Location location = CurrentValue.getDevLocation(this);
        String saddr = String.format("%f,%f", location.getLatitude(),
                location.getLongitude());
        String daddr = data.getBusiness().getAddress() + ", "
                + getCszForSearch(data);
        if (data.getLatE6() != 0
                && data.getLonE6() != 0) {
            daddr = String.format("%f,%f",
                    cdata.getLatE6() / 1000000f, data.getLonE6() / 1000000f);
        }

        startGoogleDirections(this, saddr, daddr);
    }



    public static void startGoogleDirections(Activity activity, String saddr,
            String daddr) {

        Uri.Builder builder = new Uri.Builder();
        builder.encodedPath("http://maps.google.com/maps")
                .appendQueryParameter("f", "d")
                .appendQueryParameter("hl", "en");
        // from can be null
        if (!isEmpty(saddr)) {
            builder.appendQueryParameter("saddr", saddr);
        }
        // to can be null
        if (!isEmpty(daddr)) {
            builder.appendQueryParameter("daddr", daddr);
        }

        Uri uri = Uri.parse(builder.build().toString());
        Intent i = new Intent(Intent.ACTION_VIEW, uri);
        if (i != null) {
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            activity.startActivityForResult(i,0);
        }
    }

你可能感兴趣的:(android,String,Google,null)