谷歌地图与当前的GPS位置

时间:2014-06-13 11:06:17

标签: android google-maps

我能够显示当前GPS位置的地图,现在我想将该位置发送给其他用户,例如我们可以将其带到Facebook。我试过这样做,但我无法发送,但是我得到了字符串,但我可以发送帖子。

 public void onLocationChanged(Location location) {

    TextView tvLocation = (TextView) findViewById(R.id.tv_location);

    // Getting latitude of the current location
    double latitude = location.getLatitude();

    // Getting longitude of the current location
    double longitude = location.getLongitude();

    // Creating a LatLng object for the current location
    LatLng latLng = new LatLng(latitude, longitude);

    // Showing the current location in Google Map
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

    // Zoom in the Google Map
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

    // Setting latitude and longitude in the TextView tv_location
    tvLocation.setText("Latitude:" +  latitude  + ", Longitude:"+ longitude );

}

2 个答案:

答案 0 :(得分:0)

public LatLng getLocation()
{
 // Get the location manager
 LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
 Criteria criteria = new Criteria();
 String bestProvider = locationManager.getBestProvider(criteria, false);
 Location location = locationManager.getLastKnownLocation(bestProvider);
 Double lat,lon;
 try {
   lat = location.getLatitude ();
   lon = location.getLongitude ();
   return new LatLng(lat, lon);
 }
 catch (NullPointerException e){
     e.printStackTrace();
   return null;
 }
}

答案 1 :(得分:0)