开始导航到存储在数据库中的位置 [英] start navigating to position which is stored in database

查看:132
本文介绍了开始导航到存储在数据库中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里我得到的纬度和经度坐标的应用程序。

I have an application where I am getting the latitude and longitude coordinates.

我想,当preSS一键启动导航到该位置。

I want , when to press a button to start navigating to that position .

现在,我存储在数据库中的经度和纬度。

Now , I am storing latitude and longitude in database.

所以,我想提取first.When我preSS按钮来浏览我打开一个alertdialog并在位置是我做的:

So , I want to extract the location first.When I press the button to navigate I open an alertdialog and in 'YES' I do:

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();

 }

我的存储位置(纬度和经度),我要开始导航到该位置。 我该怎么办呢?

I have the location stored (lat and lon) and i want to start navigating to that position. How can I do that?

谢谢!

---------------------更新------------------------- ------------

---------------------UPDATE-------------------------------------

如果我做某事这样的:

    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);

这样做的目的开始和我在地图应用中的启动点是S我上面定义的,但目标点是0.0,0.0中的F和;

The intent starts and I am in the map application where the start points are the "f" and "s" I defined above but the destination points are 0.0 , 0.0 ;

所以,我有2个问题:

1)如何把到目标指向我的存储位置(mylatitude,mylongitude(我复制到mylat,mylon)

1) How to put to destination points my stored locations (mylatitude ,mylongitude (which I copy to mylat,mylon)

2)如何获得当前位置(起始站),因为我的GPS类不上正常工作。

2) How to get current location (initial points) because my gps class doesn't work on that.

推荐答案

在以下 ImplLocationService 的例子是在我的应用程序正在提供经度和纬度的一类/服务协调装置内的当前位置。该位置类是类似于Android的产品,但略有不同,并提供目标经纬度坐标。如果你是从数据库中提取这些值,下面的方法是一样的。

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);

这篇关于开始导航到存储在数据库中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆