代码之家  ›  专栏  ›  技术社区  ›  Jayce

android谷歌地图lat/long

  •  3
  • Jayce  · 技术社区  · 12 年前

    我正在编写一个应用程序,将地址输入转换为纬度/经度坐标,然后在地图上显示给用户。一切都很好,除了我的坐标像。。35429885,-9745332 .. 你看,没有时间来定义它们。我需要他们像这样出来。。35.429885、-97.45332,以便googlemapsapi显示标记。有没有方法输入周期,或者我的代码有问题?下面是我用来将地址转换为lag/long的代码。提前感谢。

    geocoder = new Geocoder(this);
    
    EditText locale = (EditText) findViewById(R.id.e_addy_text);  
    
    String locationName = locale.getText().toString();
    
                try
                {
                    List<Address> addressList = geocoder.getFromLocationName(  
                        locationName, 5); 
    
                    if (addressList != null && addressList.size() > 0) 
                    {  
                        lat = (int) (addressList.get(0).getLatitude() * 1e6);  
                        lng = (int) (addressList.get(0).getLongitude() * 1e6); 
    
                        // CONVERT TO STRING
                        e_lat = Integer.toString(lat);
                        e_lng = Integer.toString(lng);
    
                        // input into my database.
                    }
                    else
                    {
                        // toast saying invalid address
                    }
                } 
                catch (Exception e) 
                {  
                    e.printStackTrace();  
                }
    
    2 回复  |  直到 12 年前
        1
  •  1
  •   Nambi    12 年前

    getLatitude() 和 getLongitude() 返回具有十进制表示形式的双精度值。 在这张图中,你将替身掷向int。

    只需将值存储在双变量中,然后转换为字符串

    double lat=addressList.get(0).getLatitude();
    
    double lon=addressList.get(0).getLongitude();
    

    转换为字符串

     e_lat=  String.valueOf(lat);
     e_lng  String.valueOf(lon);
    
        2
  •  0
  •   DjP    12 年前

    您已将lat-long存储为整数,必须将其存储为双精度