Uncaught TypeError: Cannot read property 'lat' of undefined React.JS
Uncaught TypeError: Cannot read property 'lat' of undefined React.JS
我有这段获取用户位置的代码,但是当用户不接受权限时,它会发送问题的错误,如果用户将其留空,我该如何为其赋值?
const request = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
type: "sso",
...state,
card: cifrado,
latitud: location.coordinates.lat,
longitud: location.coordinates.lng,
aceptacion: location.aceptacion
}),
latitud: location.coordinates.lat,
longitud: location.coordinates.lng,
aceptacion: location.aceptacion
}
latitud: location?.coordinates.lat || '',
longitud: location?.coordinates.lng || '',
或
body: JSON.stringify({
type: "sso",
...state,
card: cifrado,
...(location.cooridantes ? {
latitud: location.coordinates.lat,
longitud: location.coordinates.lng
} : {}),
aceptacion: location.aceptacion
})
我有这段获取用户位置的代码,但是当用户不接受权限时,它会发送问题的错误,如果用户将其留空,我该如何为其赋值?
const request = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
type: "sso",
...state,
card: cifrado,
latitud: location.coordinates.lat,
longitud: location.coordinates.lng,
aceptacion: location.aceptacion
}),
latitud: location.coordinates.lat,
longitud: location.coordinates.lng,
aceptacion: location.aceptacion
}
latitud: location?.coordinates.lat || '',
longitud: location?.coordinates.lng || '',
或
body: JSON.stringify({
type: "sso",
...state,
card: cifrado,
...(location.cooridantes ? {
latitud: location.coordinates.lat,
longitud: location.coordinates.lng
} : {}),
aceptacion: location.aceptacion
})