I cant seem to set the latitude and longitude from toDoData1 and toDoData2. I get the error of Value for latitude cannot be cast from ReadableNativeArray to Double
Can anyone suggest a idea on how do I solve the following? I am able to extract the latitude and longitude from my firebase realtime db but I cant put it for the map region’s latitude and longitude via toDoData1 and toDoData2.
The data seems to be able to be extracted and store in toDoData1 and toDoData2 but it just cannot be pass over to the MapRegion’s latitude and longitude. Am I missing a step in between?
Nowhere in the code you have posted is there any reference to coordinate (mentioned in the error message.) So I can’t see how you’re setting it and what you’re setting it to.
But I suspect you’re trying to use the latitude/longitude for the marker before they have a value.
You should instead not display the marker if the latitude and longitude are not yet set.
Here’s an old Stack Overflow question about the same issue:
The answers there initialize the latitude and longitude to 0. But that will initially put the marker off the coast of Africa:
But I have the error of ReferenceError: Can’t find variable: latitude
May I ask which longitude and longitude is this referring to? I am quite confuse at the moment.
I assume is the toDoData1 (Has the value of 1.34671) and toDoData2 (Has the value of 103.68066)
I get the same error (Screenshot of the app) in my previous comment.
I dont know if this will help or not but my intention on this page is to put 2 markers. 1 marker is for the current location (MapRegionNow) of the user using the app and the 2nd marker is for the destination (MapRegion). This destination, latitude and longitude values are extracted from firebase realtime database.
The above code means “if toDoData1 and toDoData2 both contain something other than null, undefined or false then show the marker. Otherwise don’t show the marker.”
OK, basically you just need to make sure that your latitude and longitude values are valid when you render the <Marker />. If they are not valid then you can avoid rendering the marker as above.
Oh! Finally it work. Thanks for the explanation and thank you very much ! I understand now but mind if I ask a few question regarding this mapview? I am new at this and I am still trying to learn.
Currently my code
The MapRegionNow is for my current location. How do I make this marker for MapRegionNow appear after I click the button of Get Location . Because now it just appears in my screen without me clicking the button
Is it possible to create a path between the 2 markers?
(You could check both lat and long, but one is enough.)
You are calling userLocation() in the useEffect hook, so it will automatically do that without the user pressing the button:
If you remove that userLocation() call then it won’t run until the user presses the button.
Sorry, I don’t know. Actually all of your questions in this thread are unrelated to Expo so this is not the best place to ask them. You should ask questions like this in a community dedicated to React Native Maps if there is one, or else a place like Stack Overflow.
I actually tried to did the similar trick that you have suggested in the earlier problem but it just pop up with all sorts of new error that I never see before which is why I pop the question on this issue.
Regarding the 2nd issue, it’s okay ! Thanks for willing to help me on this, giving me a clear explanation for the issues that I am asking. Really, thanks a lot ! I’m very grateful for that. This is because I am a beginner in developing a app using expo, actually my first time and the documents can be overwhelming for me which is why I don’t understand some stuff despite referring to documents/youtube guides/forums.
Regarding about posting question like this, I thought this Expo Location is under Expo SDK according to API Reference - Expo Documentation at the left hand side under Expo SDK so I thought it should be okay to post under Expo SDK. I actually did tried posting on Stack Overflow about 12 hours ago to look for a way to solve the issues but no one reply. So I tried posting the issue here hoping someone can guide me into fixing the issue I am. So thank you very much !
Yes, I understand It takes a while to figure things out.
Yes, Expo Location is part of the Expo SDK, but your questions were not actually about that. Your questions were more about React and JavaScript than Expo Location. I understand that it might not always be easy to know for sure, especially if you’re a beginner.
Oh, and feel free to post your working code as an answer under your Stack Overflow question.
It’s not disallowed, but the purpose of these forums is to discuss things specific to Expo. If something is not specific to Expo then it’s best to discuss them elsewhere.
Unfortunately not every question is answered here. If your question is actually about JavaScript or React and not specifically about Expo then there is a lower chance that someone will spend time answering it. (Or that’s what I suspect.)