0
cmap.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {   System.out.println("Cmap initial:=lat:-"+lat+" lang:-"+lon);
            Toast t=Toast.makeText(getBaseContext(),"Location"+lat+"lang:-"+lon,Toast.LENGTH_LONG);
            t.show();
            tlname=elname.getText().toString();
            tladdr=eladdr.getText().toString();
            addressInput=tlname+" "+tladdr;
            System.out.println("address:-"+addressInput);
            Toast t3=Toast.makeText(getBaseContext(),"Address"+addressInput,Toast.LENGTH_LONG);
            t3.show();
            try
            {
                Geocoder gc1 = new Geocoder(
                        getBaseContext(), Locale.getDefault());

                foundAdresses = gc1.getFromLocationName(addressInput, 5);
                showAdressResults.sendEmptyMessage(0);
                Toast t1=Toast.makeText(getBaseContext(),"Location...."+foundAdresses,Toast.LENGTH_LONG);
                t1.show();
                System.out.println("faddress:-"+foundAdresses);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (foundAdresses.size() == 0)
            { // if no address found,
                // display an error
                Dialog locationError = new AlertDialog.Builder(
                        Gotask.this).setIcon(0).setTitle(
                        "Error").setPositiveButton(R.string.ok, null)
                        .setMessage(
                        "Sorry, your address doesn't exist.")
                        .create();
                locationError.show();

            } else 
            { // else display address on map
                for (int i = 0; i < foundAdresses.size(); ++i)
                {

                    Address x = foundAdresses.get(i);
                    lat =  (x.getLatitude() *100);
                    lon = (float) x.getLongitude();
                    System.out.println("Cmap:=lat:-"+lat+" lang:-"+lon);


                }
                navigateToLocation((lat * 1000000), (lon * 1000000),myMap);
            }


        }

    });
4

2 回答 2

1

我在反向地理编码中也遇到过这种问题,所以我使用谷歌 api。请参阅此链接以获取google api 以用于反向地理编码。

于 2012-01-26T12:52:32.167 回答
0

我在开发基于谷歌地图的应用程序时遇到了同样的问题。问题出在设备上,我正在使用的设备不支持负责工作的后端服务(设备附带的一种服务)地理编码相关的 API。所以我决定使用谷歌公开的服务来查询所需地址的纬度和经度。所以试一试。

请参阅此链接以了解更多信息

http://code.google.com/apis/maps/documentation/geocoding/

请参考以下链接:

如何判断 Android 设备何时具有 Geocoder 后端服务?

安卓; 地理编码器,为什么我得到“服务不可用”?

这是解析 Xml 输出后从响应中获取纬度和经度的地理编码请求的示例请求。

http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false

前面提到的链接中有一个明确的示例。

于 2011-04-05T11:34:17.493 回答