綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 經緯度轉成地址

[複製連結] 查看: 6068|回覆: 3|好評: 1
跳轉到指定樓層
樓主
chihhao81 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2013-12-27 19:59

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
想請問高手:

我用網路上的範例程式,

將經緯度轉成地址,

可是把得到的地址貼到Google Map上,

跟我所在的地點都有段距離,

大概差距40~300公尺,

請問這樣的差距是正常的嗎?


取得經緯度
    private void getLocation(Location location) {        //將定位資訊顯示在畫面中
            if(location != null) {
                    TextView longitude_txt = (TextView) findViewById(R.id.longitude);
                    TextView latitude_txt = (TextView) findViewById(R.id.latitude);
                    TextView address_txt = (TextView) findViewById(R.id.address);
                  
                    Double longitude = location.getLongitude();        //取得經度
                    Double latitude = location.getLatitude();        //取得緯度
                   
                    longitude_txt.setText(String.valueOf(longitude));
                    latitude_txt.setText(String.valueOf(latitude));
                    address_txt.setText(getAddressByLocation(location));
            }
            else {
                    Toast.makeText(this, "無法定位座標", Toast.LENGTH_LONG).show();
            }
    }


轉成地址
        public String getAddressByLocation(Location location) {
                String returnAddress = "";
                try {
                                if (location != null) {
                                    Double longitude = location.getLongitude();        //取得經度
                                    Double latitude = location.getLatitude();        //取得緯度

                                    Geocoder gc = new Geocoder(this, Locale.TRADITIONAL_CHINESE);        //地區:台灣
                                    //自經緯度取得地址
                                    List<Address> lstAddress = gc.getFromLocation(latitude, longitude, 1);

                                    if (!Geocoder.isPresent()){ //Since: API Level 9
                                            returnAddress = "Sorry! Geocoder service not Present.";
                                    }
                                    returnAddress = lstAddress.get(0).getAddressLine(0);
                                }
                }
                catch(Exception e) {
                        e.printStackTrace();
                }
                return returnAddress;
        }
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
lkk47 | 收聽TA | 只看該作者
發表於 2013-12-30 00:28
有可能你得到的經緯度是正確的點  只是gps定位偏移了  我做過gps定位也會偏移  我上網查好像有偏移算法  但這我沒研究

評分

參與人數 1幫助 +1 收起 理由
chihhao81 + 1 3Q

查看全部評分

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
mike110631 | 收聽TA | 只看該作者
發表於 2014-1-6 11:29
在室內不精準 -> 合理
在室外不精準 -> 不太可能

評分

參與人數 1幫助 +1 收起 理由
chihhao81 + 1 3Q

查看全部評分

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
lkk47 | 收聽TA | 只看該作者
發表於 2014-1-9 20:18
你去下載  我的足跡 apk  看看有多精準 就知道了
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則