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