How to get the current location in Google Maps Android API v2?

前端 未结 13 1134
Happy的楠姐
Happy的楠姐 2020-11-27 12:32

Using

mMap.setMyLocationEnabled(true)

can set the myLocation layer enable.
But the problem is how to get the myLocation when the user

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 13:22

    Try This

    public class MyLocationListener implements LocationListener
    {
    
     @Override
    
    public void onLocationChanged(Location loc)
    {
    
    loc.getLatitude();
    
    loc.getLongitude();
    
    String Text = “My current location is: ” +
    
    “Latitud = ” + loc.getLatitude() +
    
    “Longitud = ” + loc.getLongitude();
    
    Toast.makeText( getApplicationContext(),Text,   Toast.LENGTH_SHORT).show();
    
    
    
    tvlat.setText(“”+loc.getLatitude());
    
    tvlong.setText(“”+loc.getLongitude());
    
    this.gpsCurrentLocation();
    
    }
    

提交回复
热议问题