0

緯度と経度の座標を取得するアプリケーションがあります。

いつボタンを押して、その位置へのナビゲートを開始するかを知りたいです。

現在、緯度と経度をデータベースに保存しています。

そのため、最初に場所を抽出したいと思います。ボタンを押してナビゲートすると、アラートダイアログが開き、「はい」で次のようになります。

public void navigation(final View v){



     AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
        alt_bld.setMessage("Do you want to navigate to the saved position?")
                .setCancelable(false)
                .setPositiveButton("Navigate",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {

                        // Action for 'Yes' Button

                        String query = "SELECT latitude,longitude FROM MEMORIES ";
                        Cursor c1 = sqlHandler.selectQuery(query);

                        if (c1 != null && c1.getCount() != 0) {
                            if (c1.moveToFirst()) {
                                do {                
        String mylatitude=c1.getString(c1.getColumnIndex("latitude"));
        String mylongitude=c1.getString(c1.getColumnIndex("longitude"));

        Double lat=Double.parseDouble(mylatitude);
        Double lon=Double.parseDouble(mylongitude); 


                                    } while (c1.moveToNext());
                                }
                            }

                            c1.close();


            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                    Uri.parse("http://maps.google.com/maps?saddr=" + 
                    gps.getLocation().getLatitude() + "," + 
                    gps.getLocation().getLongitude() + "&daddr=" + mylatitude + "," + mylongitude ));
                    startActivity(intent);


                            }
                        })
                .setNegativeButton("Cancel",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                // Action for 'NO' Button
                                dialog.cancel();
                            }
                        });
        AlertDialog alert = alt_bld.create();
        // Title for AlertDialog
        alert.setTitle("Navigation");
        alert.show();

 }

場所 (緯度と経度) が保存されており、その位置への移動を開始したいと考えています。どうやってやるの?

ありがとう!

- - - - - - - - - - -アップデート - - - - - - - - - - - - - - ----------

私が好きなら:

    String mylat="";
String mylon="";


@Override
protected void onCreate(Bundle savedInstanceState) {
...
...
public void navigation(final View v){
....
String mylatitude=c1.getString(c1.getColumnIndex("latitude"));
String mylongitude=c1.getString(c1.getColumnIndex("longitude"));


mylat=mylatitude;//stored coordinates from database 
mylon=mylongitude;

String f="45.08" //current location (start points)
String s="23.3";

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=" + 
f + "," + 
s + "&daddr=" + mylat + "," + mylon ));
startActivity(intent);

インテントが開始し、地図アプリケーションにいます。開始点は上で定義した「f」と「s」ですが、目的点は 0.0 、 0.0 です。

だから、私は2つの問題があります:

1)保存した場所(mylatitude、mylongitude(mylat、mylonにコピー)を目的地に配置する方法)

2) GPS クラスが機能しないため、現在の位置 (初期ポイント) を取得する方法。

4

3 に答える 3

1

In the example below ImplLocationService is a class/service within my application that is providing the latitude and longitude coordinates of the current location within the device. The Location class is similar to Android's offering but is slightly different and is providing the destination latitude and longitude coordinates. If you were to pull these values from a database, the approach below is the same.

        Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
               Uri.parse("http://maps.google.com/maps?saddr=" + 
               ImplLocationService.getCurrentLocation().getLatitude() + "," + 
               ImplLocationService.getCurrentLocation().getLongitude() + "&daddr=" + 
               location.getPoint().latitude + "," + location.getPoint().longitude));
        startActivity(intent);
于 2013-05-20T14:18:22.623 に答える
1

緯度と経度を保存しながら、このように保存します...

String mylocation=latitude + ":" + longitude;

そして回収しながら

String latitude = mylocation.subString(0, myLocation.indexOf(":") -  1 );
String longitude = mylocation.subString(myLocation.indexOf(":"));

そしてそれを次のように渡します

j.putExtra("lon", longitude);
j.putExtra("lat", latitude);
于 2013-05-15T10:03:17.483 に答える