Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用地理编码器的反向地址_Android_Google Maps_Reverse Geocoding - Fatal编程技术网

Android 使用地理编码器的反向地址

Android 使用地理编码器的反向地址,android,google-maps,reverse-geocoding,Android,Google Maps,Reverse Geocoding,我正在尝试获取一个特定地质点的地址,但当我尝试使用try-and-catch时,它失败了。这是我的代码 srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),(int) (src_long * 1E6)); Geocoder geocoder=new Geocoder(getBaseContext(), Locale.getDefault()); try { List<

我正在尝试获取一个特定地质点的地址,但当我尝试使用try-and-catch时,它失败了。这是我的代码

 srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),(int) (src_long * 1E6)); 

        Geocoder geocoder=new Geocoder(getBaseContext(), Locale.getDefault());
        try
        {
            List<Address> addresses=geocoder.getFromLocation(srcGeoPoint.getLatitudeE6()/1E6,
                    srcGeoPoint.getLongitudeE6()/1E6,1);
            String add="";
            if(addresses.size()>0)
            {
                for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); 
                        i++)
                      add += addresses.get(0).getAddressLine(i) + "\n";
            }
            tv.setText(add);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
srceopoint=新的地质点((int)(src_lat*1E6),(int)(src_long*1E6));
Geocoder Geocoder=新的地理编码器(getBaseContext(),Locale.getDefault());
尝试
{
列表地址=geocoder.getFromLocation(srcGeoPoint.getLatitudeE6()/1E6,
srceopoint.getLongitudeE6()/1E6,1);
字符串add=“”;
如果(地址.size()>0)
{

对于(int i=0;i,地理编码器不能在模拟器中工作,如下所述:


我自己也实现了,它实际上不是在模拟器中实现的,而是在设备上实现的。

地理编码器在模拟器中不起作用,如下所述:


我自己也实现了,它实际上不是在模拟器中实现的,而是在设备上实现的。

您可以将这些转换为双倍:

srcGeoPoint.getLatitudeE6()/1E6
srcGeoPoint.getLongitudeE6()/1E6
完整代码:

List addresses=geocoder.getFromLocation((double) (srcGeoPoint.getLatitudeE6()/1E6), (double) (srcGeoPoint.getLongitudeE6()/1E6),1);

你可以把这些投给双打:

srcGeoPoint.getLatitudeE6()/1E6
srcGeoPoint.getLongitudeE6()/1E6
完整代码:

List addresses=geocoder.getFromLocation((double) (srcGeoPoint.getLatitudeE6()/1E6), (double) (srcGeoPoint.getLongitudeE6()/1E6),1);

我还没有批准答案的权力,但迭戈是100%正确的,geocoder不在模拟器上工作。如果你想调试它,你必须使用真实的设备。相信我,在我发现问题之前,我的头撞到墙上花了最长的时间。所以帮你自己一个忙,这样你就不会受到脑震荡,只要使用真实的设备就行了

我还没有批准答案的权力,但迭戈是100%正确的,geocoder不在模拟器上工作。如果你想调试它,你必须使用真实的设备。相信我,在我发现错误之前,我的头撞到墙上花了最长的时间。所以帮你自己一个忙,这样你就不会受到脑震荡,只要使用真实的device

这在模拟器上很常见。您在真实设备上试用过吗?还没有,但我正在使用静态geopoint为什么不显示地址?这在模拟器上很常见。您在真实设备上试用过吗?还没有,但我正在使用静态geopoint为什么不显示地址?