-
-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get user location through browser #392
Comments
Hi @lionelquirynen, at the moment we do not have an implementation for the web platform. We would like to support this and are open for pull requests. For future reference here are two article from the Flutter team describing how to add Web support to plugins: |
@mvanbeusekom If I find some time to learn how to do it I could give it a try. Right now I found a way to do it via the js package. I post quickly the code here if someone wants it right away :
You just have to call the method _getCurrentLocation. |
@lionelquirynen Can you post your pubspec.yaml? I'm trying to add the line: import 'package:Shared/locationJs.dart'; as you posted it on stackexchange, but I'm getting errors. Did you create a Shared folder at the root level? |
Hello @lionelquirynen! First, I want to thank you for posting your solution here. I think you helped a lot of people with your message! However, I still had two questions. You may also have come across these problems and already have a solution. 1.) Have you already found a way to ask visitors of the website for permission to query their location? 2.) Have you already built a function that calculates the distance between two points in meters? I would definitely be happy if you would answer! You would help me very much! |
@xpat yes I've a folder where the locationJs file is located, sorry I just saw your message today. |
@LarsHenning98
Let me know if I answered your question ! |
@lionelquirynen Thanks, I'm running around in circles trying to figure out how to make this work for a class project. I've got the pubspec.yaml working and I've imported the file locationJS.dart in my loading_screen.dart file. Anyway, perhaps you're able to easily see how to make this work. Meanwhile, I'll keep plugging away. Here's a link to the message I posted on the class bulletin board: https://www.appbrewery.co/courses/548873/lectures/9989052/comments/5326630 FYI @LarsHenning98 |
Could you post your pubspec and your loading screen ? |
@lionelquirynen Yes, the pubspec: `name: clima
|
@lionelquirynen and the loading_screen.dart:
|
You dont call the method, thats why, you should put it in InitState |
@lionelquirynen Thanks for the help. I hate to have to rely on you (or anyone else), but I'm still confused about which file to put it in or call it from. Here's a link to the full project.. And this comes from the 13th module in the Complete Flutter Development Bootcamp, which unfortunately was made before flutter web. |
You could call the method getcurrentposition in onpressed because I dont see anywhere the call to the method, you should call it somewhere to trigger the location request |
That's where I'm getting stuck. I just updated the loading_screen.dart file in case you want to take a look at what I'm trying, based on how I understand your suggestion. In Dart Analysis I'm getting an info message: "The declaration ' getCurrentPosition' isn't referenced, and that the packages js.dart and clima/locationJS.dart aren't used, and then the print(value.coords.latitude) and the print(value.coords.longitude) are underlined grey squiggly and the message reads "Set literals weren't support until version 2.2, but this code is required to be able to run on earlier versions." |
Is your locationjs up to date ? |
I'm using the code you published on stackoverflow, if that's what you mean? I'll run flutter pub get again, but yes, I believe it is up to date. |
Did you paste the code from github not stackoverflow ?
Le ven. 28 févr. 2020 à 21:53, Christophe R. Patraldo <
notifications@github.com> a écrit :
… I'll run flutter pub get again, but yes, I believe it is up to date.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#392?email_source=notifications&email_token=ANUIRZMOEPTHHNBI7NDU3G3RFF2TJA5CNFSM4KURNFD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENKDZHY#issuecomment-592723103>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANUIRZLLEKQ2CKHF2A7VUIDRFF2TJANCNFSM4KURNFDQ>
.
|
I mean the .dart |
You should use the code I posted on github, above. I Should update my answer on stackoverflow. |
I focused on the stackoverflow code because it was easier to grasp. But now I've updated the loading_screen.dart and the locationJS.dart files with your code from Github. I'm getting errors Undefined name 'pos' and the method 'success' isn't defined for the class '_LoadingScreenState' and the method '_getCurrentLocation' isn't defined for the class '_LoadingScreenState.'
|
|
Look at my code in github on how to use it |
The errors I'm getting are after I've used the code you posted on Github (above). I've been at a loss as to how exactly to add that code to my project (which I'm building with flutter web). For instance, where do I put the part that begins with success? I tried putting it here: class _LoadingScreenState extends State { Do you have a public repository with your complete project code? |
No it's not public but above I posted the code : success(pos) { So you copy paste this code and all you have to do is to call _getCurrentLocation() in your onPressed method.. |
Does this code go in the locationJS.dart file or the loading_screen.dart? `And to call this : success(pos) { |
In the loading_screen ! Did you understand how it worked? |
I may be getting there. I just had Dart Analysis (Android Studio) create Function Function(GeoLocationPosition pos) get success => null; I'll see what I can make of that. But no, I don't really have a grasp of what's going on. This problem -- getting geolocation for the web -- has been a real challenge for me. At times I feel as if I have learned only the bare minimum in my Flutter Bootcamp. So when I add the lines that begin with success, well it's completely trial and error. I don't know where to put them. |
I'm making progress. I finally got the code to pop up a permission's window. And it's printing a message to the console. Thanks for your help and encouragement. I think it's finally starting to work, and once it does, I'll try and make sense of it. Hopefully this geolocator plugin will be updated for flutter web. Meanwhile, thanks again for your time, @lionelquirynen |
Ok perfect ! Hope u don't get too confused, let me know if you need guidance ! |
Here is a working implementation for web: |
I want to get user location on flutter web but Mozilla GeoLocation not work !!!Can some one help me? |
Is there any news or anything about web support of this package?! |
Hi, I was wondering if this plugins allowed to get the user's location through the browser? I did not find any informations about it ? Is there another plugins who allows it? Thanks in advance for the help !
The text was updated successfully, but these errors were encountered: