0

我目前正在检索我的应用程序中的当前位置,但我还需要此位置的文本,或至少是我所在的城市,类似的东西。使用Google Maps API v2获取当前位置为TEXT

有没有任何已知的方法可以做到这一点?

这是我到目前为止有:

package ro.gebs.captoom.activities; 

import android.app.Activity; 
import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.view.Window; 

import com.example.captoom.R; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class LocationActivity extends Activity { 

    private GoogleMap map; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 
     getActionBar().hide(); 
     setContentView(R.layout.preview_location); 

     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) 
       .getMap(); 

     LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); 
     Criteria criteria = new Criteria(); 
     String provider = service.getBestProvider(criteria, false); 
     Location location = service.getLastKnownLocation(provider); 
     LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude()); 


     if (map != null) { 
      Marker current_location_marker = map.addMarker(new MarkerOptions().position(userLocation) 
         .title("Current Location")); 
     } else { 

     } 

     map.moveCamera(
       CameraUpdateFactory.newLatLngZoom(userLocation, 10)); 

     // Zoom in, animating the camera. 
     map.animateCamera(
       CameraUpdateFactory.zoomTo(10), 2000, null); 

    } 

} 
+1

你可能想看看http://developer.android.com/reference/android/location/Geocoder.html得到address,并使用getFromLocation( ) 方法? – iaindownie

+0

是的,那正是我在找的,非常感谢! –

+0

好东西 - 如果它是你正在寻找的答案,再加上它? – iaindownie

回答

1

首先,你必须让你的当前latitudelongitude那么你可以使用google api得到当前地址的组成部分。看到这个问题,我的回答从lat long

Get the particular address using latitude and longitude

+0

不错的解决方案,我结束了使用类似的东西!谢谢! –

相关问题