2016-03-02 95 views

回答

0

代碼來獲得用戶

public void getMyLocation(Activity activity) { 
    int requestPermissionsCode = 50; 
    LocationManager locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE); 
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestPermissionsCode); 
     return; 
    } 
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    if (location != null) { 
     LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); 
     if (locationListener != null) 
      locationListener.onLocationFound(latLng); 
     return; 
    } 


    locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, new SingleUpdateListener(), null); 


} 

此代碼的位置,從經緯度

public Address getLocationFromLatLng(Context context, LatLng latLng) { 
    android.location.Geocoder geoCoder = new Geocoder(context, Locale.getDefault()); 

    try { 
     return geoCoder.getFromLocation(latLng.latitude, latLng.longitude, 1).get(0); 
    } catch (IOException e) { 
     return null; 
    } 

} 

獲得地址,你必須在谷歌API控制檯 註冊該應用程序的代碼for Android 6.0 plus pay attation to the listeners .. 這是一個工作代碼。

+0

我什麼時候會得到結婚和結婚..我怎樣才能展示只有100米左右的地方附近那個緯度&lng – user3218829

+0

感謝您的代碼 – user3218829

+0

使用「附近的搜索請求」[https://developers.google .com/maps/documentation/javascript/places#place_search_requests],通過調用PlacesService的nearbySearch()方法啓動Places Nearby搜索,該方法將返回一組PlaceResult對象。包含'位置'和'半徑'以表示圓的半徑(以米爲單位)。 –