GPS - 在跑步和步行时获取距离、时间 [英] GPS - Getting the distance,time while running and walking

查看:15
本文介绍了GPS - 在跑步和步行时获取距离、时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要使用 GPS 技术的情况.

i have a situation where i need to use GPS technique.

我需要在人走路时找到两点之间的距离.

i need to find the distance between two points when the person is walking.

当这个人开始走路时,他会点击开始按钮,当他停下来时,他会点击停止按钮

When the person starts walking he will click on Start button and when he stops he clicks on stop button

在这之后它应该显示给他

after this it should show him

1.time 花费2.以公里为单位行驶的距离.3.from where to where(地名) eg: a to b

1.time taken 2.Distance travelled in Kms. 3.from where to where(places name) eg: a to b

我需要谷歌地图吗?

我在这里看到了代码 link 获取当前位置,这给了我纬度经度.

I saw the code here link to get the current location which gives me latitude longitude.

请帮助解决这个问题

**

**

这是我正在使用的代码

private EditText editTextShowLocation;
    private Button buttonGetLocation;
    private ProgressBar progress;

    private LocationManager locManager;
    private LocationListener locListener = new MyLocationListener();

    private boolean gps_enabled = false;
    private boolean network_enabled = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editTextShowLocation = (EditText) findViewById(R.id.editTextShowLocation);

        progress = (ProgressBar) findViewById(R.id.progressBar1);
        progress.setVisibility(View.GONE);

        buttonGetLocation = (Button) findViewById(R.id.buttonGetLocation);
        buttonGetLocation.setOnClickListener(this);

        locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    }

    @Override
    public void onClick(View v) {
        progress.setVisibility(View.VISIBLE);
        // exceptions will be thrown if provider is not permitted.
        try {
            gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        } catch (Exception ex) {
        }
        try {
            network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
        }

        // don't start listeners if no provider is enabled
        if (!gps_enabled && !network_enabled) {
            AlertDialog.Builder builder = new Builder(this);
            builder.setTitle("Attention!");
            builder.setMessage("Sorry, location is not determined. Please enable location providers");
            builder.setPositiveButton("OK", this);
            builder.setNeutralButton("Cancel", this);
            builder.create().show();
            progress.setVisibility(View.GONE);
        }

        if (gps_enabled) {
            locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
        }
        if (network_enabled) {
            locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener);
        }
    }

    class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                // This needs to stop getting the location data and save the battery power.
                locManager.removeUpdates(locListener); 

                String londitude = "Londitude: " + location.getLongitude();
                String latitude = "Latitude: " + location.getLatitude();
                String altitiude = "Altitiude: " + location.getAltitude();
                String accuracy = "Accuracy: " + location.getAccuracy();
                String time = "Time: " + location.getTime();

                editTextShowLocation.setText(londitude + "
" + latitude + "
" + altitiude + "
" + accuracy + "
" + time);
                progress.setVisibility(View.GONE);
            } 
        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        if(which == DialogInterface.BUTTON_NEUTRAL){
            editTextShowLocation.setText("Sorry, location is not determined. To fix this please enable location providers");
        }else if (which == DialogInterface.BUTTON_POSITIVE) {
            startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        }
    }

它显示了我从 emulator control 输入的 Logitude Latitude.

在此我手动输入经度和纬度的详细信息通过转到 window->showview->other->emulator control 在模拟器中进行测试但我需要的是我将有两个编辑文本,我在其中输入地名(A)和(B)

In this i am manually entering the details of longitude and latitude by going to window->showview->other->emulator control for testing in the emulator but what i need is i will have two edittext where i enter the place name(A) and (B)

它应该给我距离

请帮忙

推荐答案

尝试使用 Google Distance Matrix Api

try using Google Distance Matrix Api

https://developers.google.com/maps/documentation/distancematrix/

这篇关于GPS - 在跑步和步行时获取距离、时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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