我使用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.583509999999933,streetName:“Leopoldstraße8”,featureTypeId:1 ...}已存档:0featureTypeId:1incidentReference:“”纬度: “48.15312”经度:11.583509999999933streetName:“Leopoldstraße8”
为什么这些变量的处理方式不同?