问题
Today I have a plan to convert an iOS app (Swift) and Android (Java+Kotlin) to React Native
.
This app show hospital as Marker on (Google)Maps based on user location.
My backend is Parser-Server
(now is ParsePlatform
)
The function bellow query the data (class) from Parse backend:
async getHospitalNearbyUser() {
const { userLocation, region } = this.state
if ((userLocation.lat !== null) && (userLocation.lng !== null)) {
const lng = userLocation.lng
const lat = userLocation.lat
const radius = 1.0
let lng_min = lng - radius / Math.abs(Math.cos(this.deg2rad(lat)) * 69)
let lng_max = lng + radius / Math.abs(Math.cos(this.deg2rad(lat)) * 69)
let lat_min = lat - (radius / 69)
let lat_max = lat + (radius / 69)
// query
const atm = Parse.Object.extend('Hospital')
let query = new Parse.Query(atm)
query.greaterThan("lat", lat_min)
query.lessThan("lat", lat_max)
query.greaterThan("lng", lng_min)
query.lessThan("lng", lng_max)
query.find()
.then(function (results) {
console.debug(results.length)
})
.catch(function (error) {
// There was an error.
console.error(error)
})
} else {
console.debug('no location')
console.debug(region)
}
}
However the error shows up is:
Error: XMLHttpRequest failed: {"line":169557, "column:32", "sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minifiy=false"
I tried to seach on Google and Parse SDK-JS on github issues but no results.
Hope some help from you.
Thanks so much !
// Update:
I am using Parse-Server that is hosted at Back4App
.
回答1:
I had the same problem,
I fixed this by changing
import {AsyncStorage} from '@react-native-community/async-storage';
to
import {AsyncStorage} from 'react-native';
来源:https://stackoverflow.com/questions/60235805/how-to-fix-error-xmlhttprequest-failed-on-react-native-with-parse-server-back