【问题标题】:Given a latitude and longitude, Get the location name给定经纬度,获取位置名称
【发布时间】:2011-05-30 05:04:27
【问题描述】:

我正在开发一个应用程序,其中我在我的 android 设备中获取纬度、经度并将它们发布到网络服务器。

在网络应用程序中,我借助谷歌地图显示位置详细信息。

在这里,我收集了大量 lat long 值,我将其循环到我的 jsp 中并使用信息窗口创建多个标记。

现在的问题是我需要在谷歌地图的信息窗口中显示特定纬度和经度的位置名称。

谁能帮助我使用 google maps 脚本,或者我如何从我的 android 手机本身的 lat long 值中获取位置名称,以便我可以将其发布到我的网络服务器。

【问题讨论】:

    标签: android google-maps gps


    【解决方案1】:

    这里给了我一个,只需在这个函数中传递纬度和经度,然后你就得到了与这个纬度和经度相关的所有信息。

    public void getAddress(double lat, double lng) {
        Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault());
        try {
            List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
            Address obj = addresses.get(0);
            String add = obj.getAddressLine(0);
            add = add + "\n" + obj.getCountryName();
            add = add + "\n" + obj.getCountryCode();
            add = add + "\n" + obj.getAdminArea();
            add = add + "\n" + obj.getPostalCode();
            add = add + "\n" + obj.getSubAdminArea();
            add = add + "\n" + obj.getLocality();
            add = add + "\n" + obj.getSubThoroughfare();
    
            Log.v("IGA", "Address" + add);
            // Toast.makeText(this, "Address=>" + add,
            // Toast.LENGTH_SHORT).show();
    
            // TennisAppActivity.showDialog(add);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
    

    【讨论】:

    • 什么是 GUIStatics,如何解决这个错误:--> GUIStatics 无法解析为变量
    • 他是对的,mahn :/ 我们需要完整的代码和解释 :(
    • 不了解此代码的人,首先获取您的纬度和经度,然后在此方法中传递这些值,您将获得有关您的位置的所有信息,这是您可以找到的链接经度和纬度.. androidhive.info/2012/07/android-gps-location-manager-tutorial 如果您不需要,请评论 GUIStatistics。我不需要,所以我只需删除并获取我的地标信息。
    【解决方案2】:
    Geocoder myLocation = new Geocoder(yourContext, Locale.getDefault());
    List<Address> myList = myLocation.getFromLocation(Double.parseDouble(latitude),Double.parseDouble(longitude), 1);
    Address address = (Address) myList.get(0);
    String addressStr = "";
    addressStr += address.getAddressLine(0) + ", ";
    addressStr += address.getAddressLine(1) + ", ";
    addressStr += address.getAddressLine(2);
    

    【讨论】:

    • 这里只是从这段代码中找到lat long,LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);位置 location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);双 m=location.getLatitude();双 n=location.getLongitude();
    【解决方案3】:
    StringBuilder _homeAddress = null;
            try{
                _homeAddress = new StringBuilder();
                Address address = null;
                List<Address> addresses = _coder.getFromLocation(_lat,_lon,1);
                for(int index=0; index<addresses.size(); ++index)
                {
                    address = addresses.get(index);
                    _homeAddress.append("Name: " + address.getLocality() + "\n");
                    _homeAddress.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
                    _homeAddress.append("Admin Area: " + address.getAdminArea() + "\n");
                    _homeAddress.append("Country: " + address.getCountryName() + "\n");
                    _homeAddress.append("Country Code: " + address.getCountryCode() + "\n");
                    _homeAddress.append("Latitude: " + address.getLatitude() + "\n");
                    _homeAddress.append("Longitude: " + address.getLongitude() + "\n\n");
                }
            }
            catch(Exception e){
                
            }
    

    【讨论】:

      【解决方案4】:

      使用android.location.geocoder.getFromLocation(double latitude, double longitude, int maxResults)

      它会给你一个地址列表。

      【讨论】:

        【解决方案5】:
         public void getAddress(double lat, double lng) {
                    Geocoder geocoder = new Geocoder(DistaceCalculating.this, Locale.getDefault());
                    try {
                        List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
                        Address obj = addresses.get(0);
                        String   add = obj.getAddressLine(0);
                        String  currentAddress = obj.getSubAdminArea() + ","
                                + obj.getAdminArea();
                        double   latitude = obj.getLatitude();
                        double longitude = obj.getLongitude();
                        String currentCity= obj.getSubAdminArea();
                        String currentState= obj.getAdminArea();
                       add = add + "\n" + obj.getCountryName();
                        add = add + "\n" + obj.getCountryCode();
                        add = add + "\n" + obj.getAdminArea();
                        add = add + "\n" + obj.getPostalCode();
                        add = add + "\n" + obj.getSubAdminArea();
                        add = add + "\n" + obj.getLocality();
                        add = add + "\n" + obj.getSubThoroughfare();
            
                        
                        System.out.println("obj.getCountryName()"+obj.getCountryName());
                        System.out.println("obj.getCountryCode()"+obj.getCountryCode());
                        System.out.println("obj.getAdminArea()"+obj.getAdminArea());
                        System.out.println("obj.getPostalCode()"+obj.getPostalCode());
                        System.out.println("obj.getSubAdminArea()"+obj.getSubAdminArea());
                        System.out.println("obj.getLocality()"+obj.getLocality());
                        System.out.println("obj.getSubThoroughfare()"+obj.getSubThoroughfare());
            
                        
                        Log.v("IGA", "Address" + add);
                        // Toast.makeText(this, "Address=>" + add,
                        // Toast.LENGTH_SHORT).show();
            
                        // TennisAppActivity.showDialog(add);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
        

        【讨论】:

          【解决方案6】:
             private String getAddress() {
                  GPSTracker   gps = new GPSTracker(ProductList.this);
                  Geocoder geocoder = new Geocoder(ProductList.this, Locale.getDefault());
                  String address="";
                  try {
                      List<Address> addresses = geocoder.getFromLocation(gps.getLatitude(), gps.getLongitude(), 1);
                      Address obj = addresses.get(0);
                      String  add = obj.getAddressLine(0);
          //optional
                    /*  add = add + "\n" + obj.getCountryName();
                      add = add + "\n" + obj.getCountryCode();
                      add = add + "\n" + obj.getAdminArea();
                      add = add + "\n" + obj.getPostalCode();
                      add = add + "\n" + obj.getSubAdminArea();
                      add = add + "\n" + obj.getLocality();
                      add = add + "\n" + obj.getSubThoroughfare();*/
          
                      Log.e("Location", "Address" + add);
                      address=add;
                      
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                  }
                  return address;
              }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2013-05-14
            • 1970-01-01
            • 2018-12-14
            • 1970-01-01
            • 2012-02-16
            • 2018-01-08
            • 2012-11-08
            相关资源
            最近更新 更多