4

私のアプリでは、ユーザーは特定の場所の緯度と経度を保存できます。正確な道順を簡単に取得できるように、Google マップなどのジオ インテントを介して携帯電話で他のアプリを起動できるようにしたいと考えています。ジオインテントを生成するために使用しているコードは次のとおりです。

public static Intent getFindIntent(Context context) {
    Intent intent = new Intent();

    SharedPreferences prefs = Tools.getPrefs(context);
    String latitude = prefs.getString(Const.LAT_KEY, "");
    String longitude = prefs.getString(Const.LONG_KEY, "");

    intent.setAction(Intent.ACTION_VIEW);
    String uri = String.format(Locale.US, "geo:%s,%s?z=%d&q=%s,%s", latitude, longitude,
            Const.ZOOM_LEVEL, latitude, longitude);


    intent.setData(Uri.parse(uri));

    return intent;
}

Google マップは携帯電話に搭載されているため、ほとんどの人が Google マップを使用することは明らかです。私が最初にアプリケーションをリリースしたとき、Google マップが起動し、インテントのデータとして設定された geo uri の q パラメータで指定された正確な座標にピンがドロップされました。Google マップ 7 のリリースにより、マップは提供された座標に最も近い住所にピンをドロップするように見えます。ユーザーは保存された位置に正確に戻ることができ、その近くの住所には戻れないため、これは私にとって問題です。これが文書化されているのを見つけた唯一の場所はここです. ドキュメントは公式の Android 開発者サイトからのものですが、非常にまばらです。この機能を提供する地理的意図に代わるものはありますか、それとも私のコードに何か問題がありますか? 住所ではなく座標を提供しているため、Google マップは API 契約を破っていると思います。

4

1 に答える 1

1

To drop the pin use this code:

 try {
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
        Uri.parse("geo:" + AppointmentDetailLayout.docLatitude
            + "," + AppointmentDetailLayout.docLongitude
            + "?q=" + AppointmentDetailLayout.docLatitude
            + "," + AppointmentDetailLayout.docLongitude
            + "(" + label + ")"));
    intent.setComponent(new ComponentName(
        "com.google.android.apps.maps",
        "com.google.android.maps.MapsActivity"));
    context.startActivity(intent);
    } catch (ActivityNotFoundException e) {

    try {
        context.startActivity(new Intent(
            Intent.ACTION_VIEW,
            Uri.parse("market://details?id=com.google.android.apps.maps")));
    } catch (android.content.ActivityNotFoundException anfe) {
        context.startActivity(new Intent(
            Intent.ACTION_VIEW,
            Uri.parse("http://play.google.com/store/apps/details?id=com.google.android.apps.maps")));
    }

    e.printStackTrace();
    }

For directions use this :

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
        Uri.parse("http://maps.google.com/maps?saddr=" + lat
            + "," + lng + "&daddr="
            + AppointmentDetailLayout.docLatitude + ","
            + AppointmentDetailLayout.docLongitude));

    context.startActivity(intent);
于 2013-09-30T12:06:57.537 に答える