Android谷歌地图。按地址添加标记 [英] Android google maps. Add marker by address

查看:104
本文介绍了Android谷歌地图。按地址添加标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android应用程序中添加了地图,并希望通过地址在地图上添加标记。有可能的?
我已经尝试过使用 Geocoder 来获得长时间的经验,但是我得到错误 Service not Available

I added map in android application and want to add marker on map by address. It is possible? I already tried to get long and lat with Geocoder, but there I get error Service not Available.

我的代码:

my code:

Geocoder geocoder = new Geocoder(getBaseContext());
        List<Address> addresses = null;

        try {
            addresses = geocoder.getFromLocationName(event.getPlace(), 20);
            System.out.println(addresses);
//          for (int i = 0; i < addresses.size(); i++) { // MULTIPLE MATCHES
//
//              Address addr = addresses.get(i);
//
//              double latitude = addr.getLatitude();
//              double longitude = addr.getLongitude(); // DO SOMETHING WITH
//                                                      // VALUES
//
//              System.out.println(latitude);
//              System.out.println(longitude);
//
//          }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


推荐答案

您的问题似乎是地理编码部分。

It is possible. Your problem seems to be the geocoding part.

使用Geocoder的问题在于它需要一个未包含在核心android框架中的后端服务,如前所述在 Android API for Geocoder 中。您应该使用 geocoder.isPresent()来检查此功能是否可用。如果不是,则不能使用此方法。

The problem with your use of Geocoder is that it requires a backend service that is not included in the core android framework, as mentioned in the Android API for Geocoder. You should use geocoder.isPresent() to check if this functionality is available. If it is not, you cannot use this method.

地理编码也可以使用URL在Google地图上完成,如 Google地理编码API 。例如(您需要一个API密钥):

Geocoding can alternatively be done with Google Maps using a URL, as described in The Google Geocoding API. For example (you need an API key):


https://maps.googleapis.com/maps/api/geocode/json?address = 1600 +露天剧场+大路,+山+视图,+ CA& key = API_KEY

被解析为检索标记的经度和纬度。

Giving a result that can be parsed to retrieve latitude and longitude for your marker.

这篇关于Android谷歌地图。按地址添加标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆