0

我有以下代码可以从纬度/经度获取方向,但它不起作用:

if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
    if (MyLocationListener.latitude > 0)
    {
        String uri = "http://maps.google.com/maps?saddr="
            + MyLocationListener.latitude + ","
            + MyLocationListener.longitude + "&daddr=37.425046,-121.906456";
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
        intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
        startActivity(intent);
    }
}
else
{
    Toast.makeText(getApplicationContext(), "Turn on GPS",Toast.LENGTH_LONG).show();
}

这是我的课:

@Override
public void onClick(View v)
{
    LocationManager mlocManager = null;
    LocationListener mlocListener;
    mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mlocListener = new MyLocationListener();
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

    public class MyLocationListener implements LocationListener
    {
        public static double latitude;
        public static double longitude;

    @Override
    public void onLocationChanged(Location loc)
    {
        loc.getLatitude();
        loc.getLongitude();
        latitude=loc.getLatitude();
        longitude=loc.getLongitude();
    }

    @Override
    public void onProviderDisabled(String provider)
    {
        //print "Currently GPS is Disabled";
    }
    @Override
    public void onProviderEnabled(String provider)
    {
        //print "GPS got Enabled";
    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)
    {
    }
}
4

0 回答 0