2015-05-22 44 views
0

我想解决问题,并且我无法确定如何。我需要通过GPS跟踪我的应用程序位置,不跟踪网络和互联网。现在,当我在外面,我有错误的立场,以非常大的分歧来找我。需要以100米的精度定位。GoogleMaps API v2 - 仅通过GPS跟踪

这里是我的活动

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> 

可有人的一部分给了我一个建议,如何可以编辑这个只通过100米的精度GPS跟踪实际位置? ?谢谢

回答

0
protected LocationManager locationManager; 

//use this on your onCreate Method 

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

on requestLocationUpdates,最后param上下文侦听器不能解决,有想法我必须改变? – Tomino

+0

“this”是指应用程序的位置侦听器。确保你有这个:'import android.location.LocationListener' – charoup

+0

好的,谢谢,坏的导入,我是从google.android.gms.maps ...我会去尝试外 – Tomino