【问题标题】:getFromLocationName() returns null on android tabletgetFromLocationName() 在 Android 平板电脑上返回 null
【发布时间】:2011-04-05 10:38:40
【问题描述】:
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);
            }


        }

    });

【问题讨论】:

  • 尝试 { Geocoder gc1 = new Geocoder(getBaseContext(), Locale.getDefault()); foundAdresses = gc1.getFromLocationName(addressInput, 5); showAdressResults.sendEmptyMessage(0); } catch (IOException e){e.printStackTrace(); }if (foundAdresses.size() == 0){err0r msg} else { for (int i = 0; i
  • 点击问题下方的编辑选项粘贴您的代码
  • 也附上你的问题陈述

标签: android tablet


【解决方案1】:

我在反向地理编码中也遇到过这种问题,所以我使用谷歌 api。 参考this link forgoogle api 用于反向地理编码。

【讨论】:

    【解决方案2】:

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

    参考此链接了解更多

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

    请参考以下链接:

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-25
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      相关资源
      最近更新 更多