Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Glad to see you are working with the Google Maps v2 API's.</p> <p>Here is a link to the GoogleMap documentation. <a href="http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html" rel="nofollow">http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html</a></p> <p>In there you will see that the api for getMyLocation() is deprecated. They recommend you to use LocationClient. Once you get the current location, use the same l1.distanceTo(locationClient.getLastLocation()), and you should be good to go. Hope this helps</p> <p>Excerpt from documentation:</p> <blockquote> <p>This method is deprecated. use LocationClient instead. LocationClient provides improved location finding and power usage and is used by the "My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder for example example code, or the Location Developer Guide.</p> </blockquote> <p>Sample Code they suggest:</p> <pre><code>public class MyLocationDemoActivity extends FragmentActivity implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener { private GoogleMap mMap; private LocationClient mLocationClient; private TextView mMessageView; // These settings are the same as the settings for the map. They will in fact give you updates at // the maximal rates currently possible. private static final LocationRequest REQUEST = LocationRequest.create() .setInterval(5000) // 5 seconds .setFastestInterval(16) // 16ms = 60fps .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_location_demo); mMessageView = (TextView) findViewById(R.id.message_text); } @Override protected void onResume() { super.onResume(); setUpMapIfNeeded(); setUpLocationClientIfNeeded(); mLocationClient.connect(); } @Override public void onPause() { super.onPause(); if (mLocationClient != null) { mLocationClient.disconnect(); } } private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setMyLocationEnabled(true); } } } private void setUpLocationClientIfNeeded() { if (mLocationClient == null) { mLocationClient = new LocationClient( getApplicationContext(), this, // ConnectionCallbacks this); // OnConnectionFailedListener } } /** * Button to get current Location. This demonstrates how to get the current Location as required, * without needing to register a LocationListener. */ public void showMyLocation(View view) { if (mLocationClient != null &amp;&amp; mLocationClient.isConnected()) { String msg = "Location = " + mLocationClient.getLastLocation(); Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); } } /** * Implementation of {@link LocationListener}. */ @Override public void onLocationChanged(Location location) { mMessageView.setText("Location = " + location); } /** * Callback called when connected to GCore. Implementation of {@link ConnectionCallbacks}. */ @Override public void onConnected(Bundle connectionHint) { mLocationClient.requestLocationUpdates( REQUEST, this); // LocationListener } /** * Callback called when disconnected from GCore. Implementation of {@link ConnectionCallbacks}. */ @Override public void onDisconnected() { // Do nothing } /** * Implementation of {@link OnConnectionFailedListener}. */ @Override public void onConnectionFailed(ConnectionResult result) { // Do nothing } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload