GoogleMaps API v2 - 仅通过GPS进行跟踪

时间:2015-05-22 15:56:49

标签: android gps google-maps-api-2

我想解决问题,我不知道怎么做。我只需通过GPS,我的应用程序跟踪位置,无需跟踪网络和互联网。现在,当我在外面时,我的位置错误,来到我身边时有很大的分歧。需要定位100米精度。

这是我的活动

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {

private boolean aFoundMyLocation;

private Document aDocument;
private GoogleMap aGoogleMap;
private GoogleDirection aGoogleDirection;

private LatLng aCurrentLocation;
...

@InjectView(R.id.txt_distance)
TextView txtDistance;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ButterKnife.inject(this);

    // initial map center settings
    aTargetLocation = new LatLng(49.199362, 18.737382);
    aGoogleDirection = new GoogleDirection(this);
    aFoundMyLocation = false;

    // inflate mapFragment
    SupportMapFragment mapFragment = (SupportMapFragment)
            getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

...

@Override
public void onMapReady(GoogleMap googleMap) {
    aGoogleMap = googleMap;
    aGoogleMap.setBuildingsEnabled(true);
    aGoogleMap.setMyLocationEnabled(true);

    aGoogleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
        @Override
        public void onMyLocationChange(Location location) {
            aCurrentLocation = new LatLng(location.getLatitude(), location.getLongitude());
            ...
            }
        }
    });
}
}

和我的清单的一部分

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
...

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="..." />

</application>

有人可以给我一个建议,怎么能编辑这个跟踪实际位置只能通过GPS精确到100米?谢谢

1 个答案:

答案 0 :(得分:0)

protected LocationManager locationManager;

//use this on your onCreate Method

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);