在android autoplace建议中我需要使用多少个API密钥?

时间:2015-10-19 06:41:54

标签: android google-maps google-maps-api-3 google-places-api

我只使用了浏览器密钥和android密钥,但它无法正常工作.... 我需要使用多少个不同的密钥进行自动提取,并从中获取LatLng,这将在建议中包含名称。

private String getAutoCompleteUrl(String place){

    // Obtain browser key from https://code.google.com/apis/console
    String key = "key=AIzaSyAVYq6kcBUABAtMIDil-8GDoDvWMi3QLnE";

    // place to be be searched
    String input = "input=" + place;

    // place type to be searched
    String types = "types=geocode";

    // Sensor enabled
    String sensor = "sensor=false";

    // Building the parameters to the web service
    String parameters = input + "&" + types + "&" + sensor + "&" + key;

    // Output format
    String output = "json";

    // Building the url to the web service
    String url = "https://maps.googleapis.com/maps/api/place/autocomplete/"
            + output + "?" + parameters;

    return url;
}
private String getPlaceDetailsUrl(String ref) {
    // Obtain browser key from https://code.google.com/apis/console
    String key = "key=AIzaSyAVYq6kcBUABAtMIDil-8GDoDvWMi3QLnE";
    // reference of place
    String reference = "reference=" + ref;
    // Sensor enabled
    String sensor = "sensor=false";
    // Building the parameters to the web service
    String parameters = reference + "&" + sensor + "&" + key;
    // Output format
    String output = "json";
    // Building the url to the web service
    String url = "https://maps.googleapis.com/maps/api/place/details/"
            + output + "?" + parameters;
    Log.d("url:",url);

    return url;
}

2 个答案:

答案 0 :(得分:0)

您只需使用浏览器api键即可使用上述方法获取自动填充位置建议 以下2个教程将帮助您更好地理解它:

http://wptrafficanalyzer.in/blog/android-autocompletetextview-with-google-places-autocomplete-api/
OR
http://codetheory.in/google-place-api-autocomplete-service-in-android-application/

但是,如果您希望在下面使用Google Places API for Android,则可以非常清楚地解释:

http://www.truiton.com/2015/04/android-places-api-autocomplete-getplacebyid/

如果您正在寻找两者之间的区别[浏览器和Android键]
这个SO Answer几乎解释了它。

希望它有所帮助!!

答案 1 :(得分:0)

我不是百分百确定这是否适用于所有情况,但是你不再需要钥匙了。所以试试这个:

字符串参数=输入+"&" +类型+"&" +传感器;