繁体   English   中英

如何在Google地图上显示自动完成结果

[英]How to display Place Autocomplete Result on Google Map

我已经实现了谷歌地图,并在地图上显示我当前的位置。

现在,我已经实现了“地方自动完成”功能,并且该“获取结果”成功获取了

 override fun onPlaceSelected(place: Place) {
    Log.i("TAG", "Place Selected: " + place.name)
    if (!TextUtils.isEmpty(place.attributions)) {
        Log.d("TAG", place.attributions.toString())
    }
 }

现在,我想在Google Map上显示此地点名称。 我们如何实现。

我认为您想在该地点的位置添加标记,并在标记的标题上显示该地点的名称。 就像是:

googleMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Your position")).showInfoWindow();

希望这可以帮助。

您可以使用以下代码实现自动完成

 var placeSearch, autocomplete;
  var componentForm = {
    street_number: 'short_name',
    route: 'long_name',
    locality: 'long_name',
    administrative_area_level_1: 'short_name',
    country: 'long_name',
    postal_code: 'short_name'
  };

  function initAutocomplete() {
    // Create the autocomplete object, restricting the search to geographical
    // location types.
    autocomplete = new google.maps.places.Autocomplete(
        /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
        {types: ['geocode']});

    // When the user selects an address from the dropdown, populate the address
    // fields in the form.
    autocomplete.addListener('place_changed', fillInAddress);
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM