我只是想使用我的API发布当前地址
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
// x.value = "" + position.coords.longitude;
// y.value = "" + position.coords.latitude;
this.locations.push({ lng: position.coords.longitude, lat: position.coords.latitude, time: local.value, picture: picture.value, publicIp : publicIp.value, privateIp: privateIp.value });
console.log(this.locations);
console.log(local.value);
$.get( "https://maps.googleapis.com/maps/api/geocode/json?latlng="+position.coords.latitude+","+position.coords.longitude+"&key=AIzaSyCCM4Cq46sTxLGAqRB1L9BmjkVuoLq05Vw", function(data) {
console.log(data);
x.value = data.results[3].address_components[0].long_name+",";
x.value += data.results[3].address_components[1].long_name+",";
x.value += data.results[3].address_components[2].long_name+",";
x.value += data.results[3].address_components[3].long_name+",";
x.value += data.results[3].address_components[4].long_name;
})
this.JsonFileService.setLogIn([{
"SourceId" : userId,
"accountId" : userId,
"latitude" : position.coords.latitude,
"longitude" : position.coords.longitude,
"privateIp" : privateIp.value,
"publicIp" : publicIp.value,
"dateTime" : local.value,
"image" : picture.value
}]).subscribe(data => {
console.log(data);
});
} else {
err.innerHTML = "Geolocation is not supported by this browser.";
}
}
未找到错误。如果我使用输入标签并放入ID,则可以在尝试将其用在angular上时获取地址,这只是显示长纬度