jQuery and Google Maps json response

后端 未结 4 1798
庸人自扰
庸人自扰 2021-01-12 21:33

I am having troubles getting geo location info from google maps api

the code is pretty straight forward

$.ajax({
    type: \"GET\",
    cache: false,         


        
4条回答
  •  时光说笑
    2021-01-12 22:08

    function codeAddress(address, title, imageURL) {
                console.log(address);
    
                geocoder.geocode({'address': address}, function (results, status) {
                    console.log(results);
                    if (status == google.maps.GeocoderStatus.OK) {
                        map.setCenter(results[0].geometry.location);
    
                            var marker = new google.maps.Marker({
                                map: map,
                                position: results[0].geometry.location,
                                icon: "",
                                title: title
                            });
    
                        /* Set onclick popup */
                        var infowindow = new google.maps.InfoWindow({content: title});
                        google.maps.event.addListener(marker, 'click', function () {
                            infowindow.open(marker.get('map'), marker);
                        });
                    }
                    else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                        setTimeout(function () {
                            codeAddress(address, title, imageURL);
                        }, 250);
                    } else {
                        alert("Geocode was not successful for the following reason: " + status);
                    }
                });
    

提交回复
热议问题