我已经设法使用 Maptiler API (OSMNames) 为表单输入提供自动完成功能(因为我发现 Google Maps API 更令人困惑)。
所以实际的问题来了,我想借助我创建的两个输入中的自动完成功能来获取我输入的两个地点之间的行驶距离。
我正在尝试使用OSRM(开源路由机) API来做到这一点
这是我当前的脚本:
<!--AUTOCOMPLETE-->
<script>
var autocomplete = new kt.OsmNamesAutocomplete(
'search1', 'https://geocoder.tilehosting.com/', '#My_Maptiler_API_Code');
</script>
<script>
var autocomplete = new kt.OsmNamesAutocomplete(
'search2', 'https://geocoder.tilehosting.com/', '#My_Maptiler_API_Code');
</script>
<!--GET INFO-->
<script>
function loadXMLDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("result").innerHTML =
this.responseText;
}
if (this.readyState == 4 && this.status == 429) {
document.getElementById("result").innerHTML =
"Server overloaded, please try again later." …Run Code Online (Sandbox Code Playgroud)