Javascript google maps autocomplete无法解析输入,因为autocomplete添加了unicode字符而不是文本

Javascript google maps autocomplete无法解析输入,因为autocomplete添加了unicode字符而不是文本,javascript,java,spring,spring-boot,google-maps,Javascript,Java,Spring,Spring Boot,Google Maps,因此,我有一个类似于spring boot应用程序的出租车网络系统,用户必须填写两个字段:“from”和“where to go”,然后我将这些地址转换为latlng并找到它们之间的路线。它以前工作正常,所以当我键入地址时,它会自动完成其他信息,如城市和国家(以前是一样的,工作正常,但现在坏了,它使用乌克兰语,并以某种方式转换乌克兰字母),这些信息会转换成一些符号,如: 原点输入:“ааааааааа、ааааа、ааааа, 目的地输入:53,53,53,53,53,53,53,53,53,5

因此,我有一个类似于spring boot应用程序的出租车网络系统,用户必须填写两个字段:“from”和“where to go”,然后我将这些地址转换为latlng并找到它们之间的路线。它以前工作正常,所以当我键入地址时,它会自动完成其他信息,如城市和国家(以前是一样的,工作正常,但现在坏了,它使用乌克兰语,并以某种方式转换乌克兰字母),这些信息会转换成一些符号,如:

原点输入:“ааааааааа、ааааа、ааааа, 目的地输入:53,53,53,53,53,53,53,53,53,53,53,53。 输入类型是什么,然后在应用程序中我收到:

我能做些什么?我需要像这样完全相同的输入:“ПППСПППССССССааааааааааааааааааааа

我有:

 @PostMapping(value = "/processInput", produces = "text/html")
    public String getOriginAndDestFromUser(@RequestParam String origin, @RequestParam String destination, Model model) throws IOException, ApiException, InterruptedException {
        model.addAttribute("origin", origin);
        model.addAttribute("destination", destination);
        model.addAttribute("cars", carService.findAll());
        model.addAttribute("carLocations", CarCoordinatsUtils.getCoords());

        String originPlaceId = getGeocodeCoordinates(origin);
        String destPlaceId = getGeocodeCoordinates(destination);
        model.addAttribute("originPlaceId", originPlaceId);
        model.addAttribute("destPlaceId", destPlaceId);

        return PagesConstants.RESPONSE_PAGE;
javascript map.html:

<script>
    // This example requires the Places library. Include the libraries=places
    // parameter when you first load the API. For example:
    // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

    function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
            center: {lat: 49.2331, lng: 28.4682},
            zoom: 13
        });
        var card = document.getElementById('pac-card');
        var input = document.getElementById('pac-input');
        var dest = document.getElementById('pac-dest');
        var types = document.getElementById('type-selector');
        var strictBounds = document.getElementById('strict-bounds-selector');

        map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);

        var autocomplete = new google.maps.places.Autocomplete(input);
        var autocomplete2 = new google.maps.places.Autocomplete(dest);

        // Bind the map's bounds (viewport) property to the autocomplete object,
        // so that the autocomplete requests use the current map bounds for the
        // bounds option in the request.
        autocomplete.bindTo('bounds', map);

        // Set the data fields to return when the user selects a place.
        autocomplete.setFields(
            ['address_components', 'geometry', 'icon', 'name']);

        var infowindow = new google.maps.InfoWindow();
        var infowindowContent = document.getElementById('infowindow-content');
        infowindow.setContent(infowindowContent);
        var marker = new google.maps.Marker({
            map: map,
            anchorPoint: new google.maps.Point(0, -29)
        });



        autocomplete.addListener('place_changed', function() {
            infowindow.close();
            marker.setVisible(false);
            var place = autocomplete.getPlace();
            if (!place.geometry) {
                // User entered the name of a Place that was not suggested and
                // pressed the Enter key, or the Place Details request failed.
                window.alert("No details available for input: '" + place.name + "'");
                return;
            }

            // If the place has a geometry, then present it on a map.
            if (place.geometry.viewport) {
                map.fitBounds(place.geometry.viewport);
            } else {
                map.setCenter(place.geometry.location);
                map.setZoom(17);  // Why 17? Because it looks good.
            }
            marker.setPosition(place.geometry.location);
            marker.setVisible(true);

            var address = '';
            if (place.address_components) {
                address = [
                    (place.address_components[0] && place.address_components[0].short_name || ''),
                    (place.address_components[1] && place.address_components[1].short_name || ''),
                    (place.address_components[2] && place.address_components[2].short_name || '')
                ].join(' ');
            }

            infowindowContent.children['place-icon'].src = place.icon;
            infowindowContent.children['place-name'].textContent = place.name;
            infowindowContent.children['place-address'].textContent = address;
            infowindow.open(map, marker);
        });

        // Sets a listener on a radio button to change the filter type on Places
        // Autocomplete.
        function setupClickListener(id, types) {
            var radioButton = document.getElementById(id);
            radioButton.addEventListener('click', function() {
                autocomplete.setTypes(types);
            });
        }

        setupClickListener('changetype-all', []);
        setupClickListener('changetype-address', ['address']);
        setupClickListener('changetype-establishment', ['establishment']);
        setupClickListener('changetype-geocode', ['geocode']);

        document.getElementById('use-strict-bounds')
            .addEventListener('click', function() {
                console.log('Checkbox clicked! New state=' + this.checked);
                autocomplete.setOptions({strictBounds: this.checked});
            });
    }
    var infoWindow = new google.maps.InfoWindow;

    // Try HTML5 geolocation.
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };

            infoWindow.setPosition(pos);
            infoWindow.setContent('Location found.');
            infoWindow.open(map);
            map.setCenter(pos);
        }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
        });
    } else {
        // Browser doesn't support Geolocation
        handleLocationError(false, infoWindow, map.getCenter());

    }

    function handleLocationError(browserHasGeolocation, infoWindow, pos) {
        infoWindow.setPosition(pos);
        infoWindow.setContent(browserHasGeolocation ?
            'Error: The Geolocation service failed.' :
            'Error: Your browser doesn\'t support geolocation.');
        infoWindow.open(map);
    }
</script>

//此示例需要Places库。包括图书馆=地方
//第一次加载API时的参数。例如:
// 
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
中心:{lat:49.2331,lng:28.4682},
缩放:13
});
var card=document.getElementById('pac-card');
var input=document.getElementById('pac-input');
var dest=document.getElementById('pac-dest');
var types=document.getElementById('type-selector');
var strictBounds=document.getElementById('strict-bounds-selector');
map.controls[google.maps.ControlPosition.TOP\u RIGHT].push(卡片);
var autocomplete=new google.maps.places.autocomplete(输入);
var autocomplete2=新的google.maps.places.Autocomplete(dest);
//将贴图的边界(视口)属性绑定到自动完成对象,
//因此,自动完成请求使用
//请求中的边界选项。
autocomplete.bindTo('bounds',map);
//设置用户选择地点时返回的数据字段。
自动完成设置字段(
['address_components','geometry','icon','name'];
var infowindow=new google.maps.infowindow();
var infowindowContent=document.getElementById('infowindow-content');
setContent(infowindowContent);
var marker=new google.maps.marker({
地图:地图,
主播点:新google.maps.Point(0,-29)
});
autocomplete.addListener('place\u changed',function(){
infowindow.close();
marker.setVisible(假);
var place=autocomplete.getPlace();
如果(!place.geometry){
//用户输入了未建议的地点的名称,然后
//按Enter键,或Place Details请求失败。
window.alert(“没有可供输入的详细信息:“+place.name+””);
返回;
}
//如果该地点有几何图形,则将其显示在地图上。
if(place.geometry.viewport){
map.fitBounds(place.geometry.viewport);
}否则{
地图。设置中心(地点。几何。位置);
map.setZoom(17);//为什么是17?因为它看起来不错。
}
标记器.设置位置(位置.几何.位置);
marker.setVisible(true);
var地址=“”;
if(位置、地址和组件){
地址=[
(place.address_components[0]&&place.address_components[0]。简称| | |“”),
(place.address_components[1]&&place.address_components[1]。简称| | |“”),
(place.address_components[2]&&place.address_components[2]。简称| |“”)
].加入(“”);
}
infowindowContent.children['place-icon'].src=place.icon;
infowindowContent.children['place-name'].textContent=place.name;
infowindowContent.children['place-address'].textContent=地址;
信息窗口。打开(地图、标记);
});
//在单选按钮上设置侦听器以更改位置上的筛选器类型
//自动完成。
功能设置ClickListener(id、类型){
var radioButton=document.getElementById(id);
radioButton.addEventListener('单击',函数()){
自动完成。设置类型(类型);
});
}
setupClickListener('changetype-all',[]);
setupClickListener('changetype-address',['address']);
setupClickListener('changetype-Establish',['Establish']);
setupClickListener('changetype-geocode',['geocode']);
document.getElementById('use-strict-bounds'))
.addEventListener('单击',函数()){
console.log('已单击复选框!新状态='+此.checked);
setOptions({strictBounds:this.checked});
});
}
var infoWindow=new google.maps.infoWindow;
//试试HTML5地理定位。
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(函数(位置){
var pos={
纬度:位置坐标纬度,
lng:position.coords.longitude
};
信息窗口。设置位置(pos);
infoWindow.setContent('找到位置');
打开(地图);
地图设置中心(pos);
},函数(){
handleLocationError(true,infoWindow,map.getCenter());
});
}否则{
//浏览器不支持地理位置
handleLocationError(错误,infoWi
 public static String getGeocodeCoordinates(String address) throws InterruptedException, ApiException, IOException {
        GeocodingApiRequest request = GeocodingApi.newRequest(getGeoContext()).address(address);
        GeocodingResult result = request.await()[0];
        return result.geometry.location.toString();

    }
<script>
    // This example requires the Places library. Include the libraries=places
    // parameter when you first load the API. For example:
    // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

    function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
            center: {lat: 49.2331, lng: 28.4682},
            zoom: 13
        });
        var card = document.getElementById('pac-card');
        var input = document.getElementById('pac-input');
        var dest = document.getElementById('pac-dest');
        var types = document.getElementById('type-selector');
        var strictBounds = document.getElementById('strict-bounds-selector');

        map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);

        var autocomplete = new google.maps.places.Autocomplete(input);
        var autocomplete2 = new google.maps.places.Autocomplete(dest);

        // Bind the map's bounds (viewport) property to the autocomplete object,
        // so that the autocomplete requests use the current map bounds for the
        // bounds option in the request.
        autocomplete.bindTo('bounds', map);

        // Set the data fields to return when the user selects a place.
        autocomplete.setFields(
            ['address_components', 'geometry', 'icon', 'name']);

        var infowindow = new google.maps.InfoWindow();
        var infowindowContent = document.getElementById('infowindow-content');
        infowindow.setContent(infowindowContent);
        var marker = new google.maps.Marker({
            map: map,
            anchorPoint: new google.maps.Point(0, -29)
        });



        autocomplete.addListener('place_changed', function() {
            infowindow.close();
            marker.setVisible(false);
            var place = autocomplete.getPlace();
            if (!place.geometry) {
                // User entered the name of a Place that was not suggested and
                // pressed the Enter key, or the Place Details request failed.
                window.alert("No details available for input: '" + place.name + "'");
                return;
            }

            // If the place has a geometry, then present it on a map.
            if (place.geometry.viewport) {
                map.fitBounds(place.geometry.viewport);
            } else {
                map.setCenter(place.geometry.location);
                map.setZoom(17);  // Why 17? Because it looks good.
            }
            marker.setPosition(place.geometry.location);
            marker.setVisible(true);

            var address = '';
            if (place.address_components) {
                address = [
                    (place.address_components[0] && place.address_components[0].short_name || ''),
                    (place.address_components[1] && place.address_components[1].short_name || ''),
                    (place.address_components[2] && place.address_components[2].short_name || '')
                ].join(' ');
            }

            infowindowContent.children['place-icon'].src = place.icon;
            infowindowContent.children['place-name'].textContent = place.name;
            infowindowContent.children['place-address'].textContent = address;
            infowindow.open(map, marker);
        });

        // Sets a listener on a radio button to change the filter type on Places
        // Autocomplete.
        function setupClickListener(id, types) {
            var radioButton = document.getElementById(id);
            radioButton.addEventListener('click', function() {
                autocomplete.setTypes(types);
            });
        }

        setupClickListener('changetype-all', []);
        setupClickListener('changetype-address', ['address']);
        setupClickListener('changetype-establishment', ['establishment']);
        setupClickListener('changetype-geocode', ['geocode']);

        document.getElementById('use-strict-bounds')
            .addEventListener('click', function() {
                console.log('Checkbox clicked! New state=' + this.checked);
                autocomplete.setOptions({strictBounds: this.checked});
            });
    }
    var infoWindow = new google.maps.InfoWindow;

    // Try HTML5 geolocation.
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };

            infoWindow.setPosition(pos);
            infoWindow.setContent('Location found.');
            infoWindow.open(map);
            map.setCenter(pos);
        }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
        });
    } else {
        // Browser doesn't support Geolocation
        handleLocationError(false, infoWindow, map.getCenter());

    }

    function handleLocationError(browserHasGeolocation, infoWindow, pos) {
        infoWindow.setPosition(pos);
        infoWindow.setContent(browserHasGeolocation ?
            'Error: The Geolocation service failed.' :
            'Error: Your browser doesn\'t support geolocation.');
        infoWindow.open(map);
    }
</script>
<script>
    var map;
    var start = document.getElementById("start");
    var end = document.getElementById("end");
    var origin = document.getElementById("origin").innerText;
    var destination = document.getElementById("destination").innerText;
    var originPlaceId = document.getElementById("originPlaceId").innerText;
    var destPlaceId = document.getElementById("destPlaceId").innerText;
    initMap();
    function initMap() {
        var directionsService = new google.maps.DirectionsService();
        var directionsRenderer = new google.maps.DirectionsRenderer();



        map = new google.maps.Map(document.getElementById('map'), {
            zoom: 12,
            center: {lat: 49.2331, lng: 28.4682},
        });
        directionsRenderer.setMap(map);

        var onChangeHandler = function() {
            console.log('goes to here 1');
            calculateAndDisplayRoute(directionsService, directionsRenderer);
        };
        document.getElementById('showDirection').addEventListener('click', onChangeHandler);
    }

    function calculateAndDisplayRoute(directionsService, directionsRenderer) {
        console.log('goes to here 2');
        directionsService.route(
            {
                 origin: {query: document.getElementById("originPlaceId").innerText}, //45.65676020,-122.60382060
                 destination: {query: document.getElementById("destPlaceId").innerText}, //49.22513880,28.41919540//var end doesnt work here and request not found, should pass ltn and lng of start and dest and works fine
                //origin : {query: "49.2261393,28.4103459"},
                //destination : {query: "49.2250969,28.4187825"},
                travelMode: 'DRIVING'
            },
            function(response, status) {
                if (status === 'OK') {
                    console.log('goes to here 3');
                    directionsRenderer.setDirections(response);

                } else {
                    console.log('goes to here fail');
                    window.alert('Directions request failed due to ' + status);
                }
            });
    }
</script>

private static void testUrlEncoding() {
    String actual = "Kosmonavtiv Avenue, 66, &#1042;&#1110;&#1085;&#1085;&#1080;&#1094;&#1103;, &#1042;&#1110;&#1085;&#1085;&#1080;&#1094;&#1100;&#1082;&#1072; &#1086;&#1073;&#1083;&#1072;&#1089;&#1090;&#1100;, &#1059;&#1082;&#1088;&#1072;&#1111;&#1085;&#1072;";
        String unescaped = StringEscapeUtils.unescapeHtml4(actual);
        System.out.println(unescaped);
}
Kosmonavtiv Avenue, 66, Вінниця, Вінницька область, Україна