本文介绍了反向地理编码不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我书面方式,需要查找当前位置的应用程序。在code将返回lattitude和经度正确,但犯规返回真实地址(反向地理编码)
可能是什么问题。
有人请帮帮忙,我是新来的Andr​​oid系统。
我与Android 4.0的模拟器上测试
updateWithNewLocation()从onLocationChanged称为(位置LOC)方法

 无效updateWithNewLocation(地点)
          {
                    如果(位置!= NULL)
                    {
                            双纬度= 29.00; // location.getLatitude();
                            双LNG = 77.0; // location.getLongitude();
                            longitudeLattitudeString =Lattitude:+纬度+经度:+ LNG;
                            地理codeR GC =新的地缘codeR(这一点,Locale.getDefault());                            尝试
                            {
                                    清单<地址>地址= gc.getFromLocation(纬度,经度,1);
                                    StringBuilder的SB =新的StringBuilder();
                                    //Toast.makeText(this,问题1,2000年).show();
                                    如果(addresses.size()大于0)
                                    {
                                            地址地址= addresses.get(0);
                                            的for(int i = 0; I< address.getMaxAddressLineIndex();我++)
                                                。sb.append(address.getAddressLine(I))追加(\\ n);
                                            。sb.append(address.getLocality())追加(\\ n);
                                            Toast.makeText(这一点,Problem2,2000年).show();
                                            。sb.append(address.getPostal code())追加(\\ n);
                                            sb.append(address.getCountryName());
                                    }
                                    其他
                                    {
                                        addressString =没有位置;
                                        //Toast.makeText(this,Problem3,2000年).show();
                                    }
                                    addressString = sb.toString();
                            }
                            赶上(IOException异常E)
                            {
                                //Toast.makeText(thisContext,问题:InCatch,2000年).show();
                            }
                    }
                    其他
                    {
                            longitudeLattitudeString =没有发现地点;                    }
            }


解决方案

反向地理编码不与仿真,对器件测试工作。

I am writting an application which needs to find the current location. The code is returning lattitude and longitude correctly but doesnt return the real address(reverse geocoding)what could be problem.Someone please help, i am new to android.I am testing on emulator with android 4.0updateWithNewLocation() is called from onLocationChanged(Location loc) method

         void updateWithNewLocation(Location location)
          {
                    if (location != null)
                    {
                            double lat = 29.00;//location.getLatitude();
                            double lng = 77.0;//location.getLongitude();
                            longitudeLattitudeString="Lattitude :"+lat+" Longitude :"+lng;


                            Geocoder gc = new Geocoder(this, Locale.getDefault());

                            try
                            {
                                    List<Address> addresses = gc.getFromLocation(lat, lng, 1);
                                    StringBuilder sb = new StringBuilder();
                                    //Toast.makeText(this, "Problem1", 2000).show();
                                    if (addresses.size() > 0)
                                    {
                                            Address address = addresses.get(0);
                                            for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
                                                sb.append(address.getAddressLine(i)).append("\n");
                                            sb.append(address.getLocality()).append("\n");
                                            Toast.makeText(this, "Problem2", 2000).show();
                                            sb.append(address.getPostalCode()).append("\n");
                                            sb.append(address.getCountryName());
                                    }
                                    else
                                    {
                                        addressString="  No Location";
                                        //Toast.makeText(this, "Problem3", 2000).show();
                                    }
                                    addressString = sb.toString();
                            }
                            catch (IOException e)
                            {
                                //Toast.makeText(thisContext, "Problem : InCatch", 2000).show();
                            }
                    }


                    else
                    {
                            longitudeLattitudeString = "No location found";

                    }




            }
解决方案

Reverse Geocoding does not work with Emulator, test on device.

这篇关于反向地理编码不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 21:24