【问题标题】:How to check Lat Long is within particular City?如何检查 Lat Long 是否在特定城市内?
【发布时间】:2016-11-17 05:59:30
【问题描述】:

我想检查我的经纬度是否属于特定城市。 我从placeAutoComplete.IntentBuilder 收到我的经纬度

try {
  Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
    .setBoundsBias(new LatLngBounds(
      new LatLng(Double.valueOf(18.5204), Double.valueOf(73.8567)),
      new LatLng(Double.valueOf(18.5204), Double.valueOf(73.8567))))
    .build(CheckOut.this);

  startActivityForResult(intent, 1);
} catch (GooglePlayServicesRepairableException e) {
  // TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
  // TODO: Handle the error.
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == 1) {
    if (resultCode == RESULT_OK) {
      Place place = PlaceAutocomplete.getPlace(this, data);
      Log.i("place", "Place: " + place.getLatLng());
      LatLng placeLatLong= place.getLatLng();
      user_lat = String.valueOf(placeLatLong.latitude);
      user_long = String.valueOf(placeLatLong.longitude);
      tvAddress2Popup.setText(String.valueOf(place.getName()));
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
      Status status = PlaceAutocomplete.getStatus(this, data);
      // TODO: Handle the error.
      Log.i("", status.getStatusMessage());
    } else if (resultCode == RESULT_CANCELED) {
      // The user canceled the operation.
    }
  }
}

请给我解决办法

【问题讨论】:

    标签: java android location


    【解决方案1】:

    我想你可以试试下面的 google api,你会得到所有特定地点的详细信息

    https://maps.googleapis.com/maps/api/place/details/json?placeid=xxxx&key=APi_key

    【讨论】:

      【解决方案2】:

      您可以使用反向地理编码http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding 查找城市名称和详细信息。

      或者您可以使用 google apis 通过纬度和经度找出所有详细信息 http://maps.googleapis.com/maps/api/geocode/json?latlng=26.8432779,77.8027763&sensor=true

      检查后您可能会找到解决方案。

      【讨论】:

        【解决方案3】:

        Geocoder geocoder;
        List<Address> addresses;
        geocoder = new Geocoder(this, Locale.getDefault());
        
        addresses = geocoder.getFromLocation(latitude, longitude, 1); 
        String address = addresses.get(0).getAddressLine(0); 
        String city = addresses.get(0).getLocality();
        String state = addresses.get(0).getAdminArea();
        String country = addresses.get(0).getCountryName();
        String postal_Code = addresses.get(0).getPostalCode();
        String Name = addresses.get(0).getFeatureName(); 

        【讨论】:

          【解决方案4】:

          你可以像这样简单地检查

          String latitudeStr = String.valueOf(address.getLatitude());
                          latitudeStr = latitudeStr.substring ( latitudeStr.indexOf ( "." ) );
          
                          String longitudeStr = String.valueOf(address.getLongitude());
                          longitudeStr = longitudeStr.substring ( longitudeStr.indexOf ( "." ) );
          
          
                          if(latitudeStr.length()>=8) {
          
                          //this is city  
                          } 
          

          通过这个你可以得到城市拉长..

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-02-09
            • 1970-01-01
            • 1970-01-01
            • 2011-02-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多