Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图API纬度和经度返回的结果不同_Javascript_Google Maps - Fatal编程技术网

Javascript 谷歌地图API纬度和经度返回的结果不同

Javascript 谷歌地图API纬度和经度返回的结果不同,javascript,google-maps,Javascript,Google Maps,我使用googleMaps API从给定地址获取位置数据: function geocodeAddress(address, callback) { var geocoder = new google.maps.Geocoder(); geocoder.geocode({ address: address }, function(results, status) { if (status === google.maps.GeocoderStatus.OK) {

我使用googleMaps API从给定地址获取位置数据:

function geocodeAddress(address, callback) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ address: address }, function(results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            if (results.length > 0) {
                callback(results[0].geometry.location);
            } else {
                console.log("No results found");
            }
        } else {
            console.log("Geocoder failed due to: " + status);
        }
    });
}

function getLatLng(address, callback) {
    latLng = [];
    geocodeAddress(address, function(position) {
        latLng.push(position.lat());
        latLng.push(position.lng());
        callback(latLng);
    });
}

// Search for address provided by user via Google Maps API
setMapToSearchAddress: function() {
    var vm = this;

    // Set the location in map to the address given
    setMapLocationToAddress(this.searchAddress);
    getLatLng(this.searchAddress, function(latlng) {
        console.log(latlng);
        vm.latitude = latlng[0];
        vm.longitude = latlng[1];
    })
}
但是,当我向服务器发送POST请求并打印所发送请求的输出时,我看到,经度是作为数字发送的,而纬度是作为字符串发送的。但我从未转换过数据

function postDataToServer(endpoint, data, callback) {
    $.post("v1/".concat(endpoint), function(data, response) {
        callback(response);
    })
}

   createIncident: function() {
        var incidentData = {
            "incidentReference": "",
            "latitude": this.latitude,
            "longitude": this.longitude,
            "streetName": this.address,
            "featureTypeId": 1,
            "archived": 0
        }

        console.log(incidentData);

        // POST data to server
        postDataToServer("incidents", incidentData, function(response) {
            console.log(response);
        })
    },
对象{incidentReference:,纬度:“48.15312”,经度: 11.58350999933,街道名称:“Leopoldstraße 8”,特征类型ID:1…}存档:0特征类型ID:1事故参考:“纬度: “48.15312”经度:11.58350999999333街道名称:“Leopoldstraße 8”


为什么这些变量的处理方式不同?

表单数据总是以字符串的形式发送,所以数据的类型(发送前)并不重要(发送JSON字符串除外)。也许这仅仅是控制台的问题(你使用的是哪个浏览器),我发现$.post似乎就是问题所在。我得到一个错误,服务器没有收到latitude属性。嗯…你确定你的服务器正在接收任何数据吗?看起来您的
$。post
语法可能不正确,因为您试图通过成功回调函数发送数据。可以尝试
$.post(“v1/”.concat(端点)、数据、函数(响应){…