getFromLocationName() 在 Android 平板电脑上返回 null

发布于 2024-10-30 06:13:29 字数 2235 浏览 1 评论 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);
            }


        }

    });
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);
            }


        }

    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云巢 2024-11-06 06:13:30

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

I have also faced this kind of issue in reverse Geo coding so i am use Google api for it.
Refer this link for google api to use in reverse geocoding.

久伴你 2024-11-06 06:13:30

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

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

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

请参阅以下链接:

如何判断 Android 设备何时具有地理编码器后端服务?

Android; Geocoder,为什么我收到“服务不可用”?

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

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

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

I faced the same problem when i was developing an app based on google maps.The problem was with the devcie ,the one which i am using did't support backend service(a kind of service comes with device) which is responsible for working of GeoCoding related APIs.So i decided to use services exposed by google to query for lat & longitude for the required Address.So just give a try.

Refer this link to know more

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

Please refer following links:

How can you tell when an Android device has a Geocoder backend service?

Android; Geocoder, why do I get "the service is not available"?

Here is a sample request for geocoding request to obtain Latitude and longitude from response after parsing Xml output.

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

There is a clear cut example in the link mentioned earlier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文