简体   繁体   English

Google Place自动完成功能的初始位置

[英]Initial place for google place autocomplete

I am using google map place autocomplete API in my application. 我在我的应用程序中使用Google Map Place自动完成API。 Now at the initial load i want to show one location on that input of autocomplete. 现在,在初始负载下,我想在自动完成输入中显示一个位置。 Is there any way i can achieve it without setting value of the text box ? 没有设置文本框的值,有什么办法可以实现?

Probably the API doesn't support anything like that. 该API可能不支持此类功能。 However, you can simulate the same by prefilling the text box with the location you want and then center your map on that location. 但是,您可以通过在文本框中预填所需的位置,然后将地图放在该位置的中央来模拟相同的内容。

For example: You can prefill the textbox with 'Bangalore, Karnataka' and center the map at 12.970786, 77.593466 (Lat and Lng of Bangalore). 例如:您可以在文本框中预填“班加罗尔,卡纳塔克邦”,并将地图居中于12.970786,77.593466(班加罗尔的Lat和Lng)。

If you already know the result of the auto complete, use that address/place and use either the geocoder, the places API or the resulting coordinates go display the result. 如果您已经知道自动完成的结果,请使用该地址/地点,然后使用地址解析器,地点API或生成的坐标来显示结果。

Although looking at your fiddle, I think this is what you are looking for (fill in the Autocomplete input with the predefined value of "Nebraska, United States": 尽管看了您的小提琴,但我认为这是您想要的(用“美国内布拉斯加州”的预定义值填写“自动完成”输入:

<input id="autocomplete" placeholder="Enter location" type="text" value="Nebraska, United States" />

proof of concept fiddle 概念证明

code snippet: 代码段:

 function initialize() { new google.maps.places.Autocomplete( (document.getElementById('autocomplete')), { types: ['geocode'] }); } initialize(); 
 #autocomplete { width: 300px; padding: 7px; } 
 <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script> <input id="autocomplete" placeholder="Enter location" type="text" value="Nebraska, United States" /> 

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

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