Forum Xamarin.Forms

gps tracker in real time like uber or cabify

HaskellHaskell MXMember ✭✭

Hello guys,
I want to made an application that you can tracking people in real time like UBER or Cabify, I don't know how can I do this, my Idea is the follow

this is my idea but I dont know if this is the correct form, please can you please help me with this? anyon

Tagged:

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I don't care for the "every second" part of that. Timers are just very 1998 thinking.
    The app can track last position to current position and update every 250 feet or so. That way you don't get bogged down with hundreds of identical GPS points when they are stuck in traffic.

    Same with map updates. Instead of timers be more event-driven, and update the map on the event of getting a new point.

  • HaskellHaskell MXMember ✭✭

    Hello Clint Thanks a lot for your answer, your idea it's better mine, but I wanna know how can I do this? in real time, is there any function or method for do this? do you have any example or link where I could check to see how do this?
    I don't know how Uber or Cabify doed this and I am very interested on know this topic.
    Regards,
    Luis

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
  • HaskellHaskell MXMember ✭✭

    ss> @ClintStLaurent said:

    An example of how I can send the position every 250 feet. Because when I run my application, my application sends the position only once. I do not know how to do this.
    And I don't know how can I refresh my map too every that I get information.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    You'll have to write code to perform that logic.
    When you get a point (however you're doing that now), save it.
    When you get another point, compare it to the previous point.
    If the difference is greater than some value (250 feet for example), then react to it.
    If not, then don't.

  • HaskellHaskell MXMember ✭✭

    @ClintStLaurent said:
    You'll have to write code to perform that logic.
    When you get a point (however you're doing that now), save it.
    When you get another point, compare it to the previous point.
    If the difference is greater than some value (250 feet for example), then react to it.
    If not, then don't.

    no no no, you are thats look like you are not understand my question, my question, my question its related with this:
    When you get another point, compare it to the previous point.
    ok here, I dotknow how can I get another point in real time, my app execute only one time, how can I do for my application send information every time without neediness I closed my app and run again, I dont know if a need use something like this: https://developer.xamarin.com/guides/ios/user_interface/controls/part_2_-_working_with_the_ui_thread/
    to my app send information everytime

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited April 2017

    Well... How are you getting the one point now? Do that again.

    UPDATE: Please paste in your code for where/how you're getting the point the first time.

    I have no idea what that link for UIthread in iOS has to do with getting the GPS point.

  • HaskellHaskell MXMember ✭✭

    @ClintStLaurent said:
    Well... How are you getting the one point now? Do that again.

    UPDATE: Please paste in your code for where/how you're getting the point the first time.

    I have no idea what that link for UIthread in iOS has to do with getting the GPS point.

      private async void Button_Start(object sender, EventArgs e)
            {
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;
                var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
    
        var Longitude = position.Longitude.ToString();
        var Latitude    position.Latitude.ToString();
    
                Label1.Text = position.Longitude.ToString();
                Label2.Text = position.Latitude.ToString();
            }
    

    Ok, as you can see, I have an Start Button, When user clicked this button, this gets the position, and saves the position in a variable.
    These variables will send to the DB with an Api. Here as you can see,** I get the position Just one time** I wanna know how can I get this information all time.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    You have this code. Got that.
    Did you write this code? Do you understand this code?

  • HaskellHaskell MXMember ✭✭

    I copied this code when I looking for know how get position, as I understand I get the position latitude and longitude, and I sabe this information on variable, as you can see on my screen:

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited April 2017

    I pointed you at a tutorial for events. Do you understand the concept of events, and reacting to events?

    You're using the Cross.Geolocator package.
    Did you read the documentation?
    https://github.com/jamesmontemagno/GeolocatorPlugin

    The service raises an event for when the position changes. Subscribe to it.
    There is an example in the documentation of updating the UI when the event is raised.

    Have you worked through some kind of "learning C#" course... Or maybe worked through a couple "Learn C# in 60 days" books? I get the impression that coding in general is new for you, not just Xamarin.

  • LannyDeVaneyLannyDeVaney USMember ✭✭

    I use a REST call to update the server on locations, that are tracked on a map server-side.

    One other thing I recently added, using the Connectivity plugin ... I declare a Queue and add my location to the queue when my changed location event fires. Then, I check for connectivity and send the location to the server. That way, if I ever lose a cellular signal, I've queued up the points (my points are in a custom object that includes user and time stamp) and can send them all to the server. A lot of folks don't realize you can still get GPS signals on your phone without a data signal.

  • HaskellHaskell MXMember ✭✭

    @LannyDeVaney said:
    I use a REST call to update the server on locations, that are tracked on a map server-side.

    One other thing I recently added, using the Connectivity plugin ... I declare a Queue and add my location to the queue when my changed location event fires. Then, I check for connectivity and send the location to the server. That way, if I ever lose a cellular signal, I've queued up the points (my points are in a custom object that includes user and time stamp) and can send them all to the server. A lot of folks don't realize you can still get GPS signals on your phone without a data signal.

    Could you please tell me how do you get the position in android at all time? I wanna know how do you send the gps point at all time if my position change get this position and send to the server.
    Regards

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Could you please tell me how do you get the position in android at all time?

    I already told you... You subscribe to the position changed event. Just like in the example on the developer site that I linked.

    Did you read the documentation?
    https://github.com/jamesmontemagno/GeolocatorPlugin
    The service raises an event for when the position changes. Subscribe to it.
    There is an example in the documentation of updating the UI when the event is raised.

    If you don't understand events... If you can't grasp the example on that site... there is little more anyone can explain to you. I might suggest learning C# first, before trying to build a program.

  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭

    @Haskell said:

    @LannyDeVaney said:
    I use a REST call to update the server on locations, that are tracked on a map server-side.

    One other thing I recently added, using the Connectivity plugin ... I declare a Queue and add my location to the queue when my changed location event fires. Then, I check for connectivity and send the location to the server. That way, if I ever lose a cellular signal, I've queued up the points (my points are in a custom object that includes user and time stamp) and can send them all to the server. A lot of folks don't realize you can still get GPS signals on your phone without a data signal.

    Could you please tell me how do you get the position in android at all time? I wanna know how do you send the gps point at all time if my position change get this position and send to the server.
    Regards

    I think we need a Server to save data of all client app from user's device. Then you can see route of user via username. Your app will access privacy data. What are you doing?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @NguyenLiem are you working with @Haskell on the same project?
    I ask because you say "we need a server"...

    If not, its impolite to hijack his thread for your needs. He is just trying to get continuous updates of current position. You're talking about saving and displaying historical data of where your users have been. Two different things.

  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭

    @ClintStLaurent said:
    @NguyenLiem are you working with @Haskell on the same project?
    I ask because you say "we need a server"...

    If not, its impolite to hijack his thread for your needs. He is just trying to get continuous updates of current position. You're talking about saving and displaying historical data of where your users have been. Two different things.

    Thank you for your help!
    I have done this app in UWP, Now I bring my app to Android maybe iOS too So I try this with Xamarin.Forms
    I'm not working with him, I only have same question. I appreciate your help. Thank you!

  • HaskellHaskell MXMember ✭✭
    edited April 2017

    Thanks guys I read more and I understand 2 things
    1._ know do services
    2._ Work with events (as Clint told me)
    I will use GeoLocator Plugin (https://github.com/jamesmontemagno/GeolocatorPlugin)

    As you can see in image below I need work with services and use these events.

    async Task StartListening()
    {
        await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 10, true, new Plugin.Geolocator.Abstractions.ListenerSettings
                    {
                        ActivityType = Plugin.Geolocator.Abstractions.ActivityType.AutomotiveNavigation,
                        AllowBackgroundUpdates = true,
                        DeferLocationUpdates = true,
                        DeferralDistanceMeters = 1,
                        DeferralTime = TimeSpan.FromSeconds(1),
                        ListenForSignificantChanges = true,
                        PauseLocationUpdatesAutomatically = false
                    });
    
        CrossGeolocator.Current.PositionChanged += Current_PositionChanged;
    }
    
    private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
    {
        Device.BeginInvokeOnMainThread(() =>
        {
            var test = e.Position;
            listenLabel.Text = "Full: Lat: " + test.Latitude.ToString() + " Long: " + test.Longitude.ToString();
            listenLabel.Text += "\n" + $"Time: {test.Timestamp.ToString()}";
            listenLabel.Text += "\n" + $"Heading: {test.Heading.ToString()}";
            listenLabel.Text += "\n" + $"Speed: {test.Speed.ToString()}";
            listenLabel.Text += "\n" + $"Accuracy: {test.Accuracy.ToString()}";
            listenLabel.Text += "\n" + $"Altitude: {test.Altitude.ToString()}";
            listenLabel.Text += "\n" + $"AltitudeAccuracy: {test.AltitudeAccuracy.ToString()}";
        });
    }           
    
    
    Thanks and Regards
    
  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭

    @Haskell said:
    Thanks guys I read more and I understand 2 things
    1._ know do services
    2._ Work with events (as Clint told me)
    I will use GeoLocator Plugin (https://github.com/jamesmontemagno/GeolocatorPlugin)

    As you can see in image below I need work with services and use these events.


    async Task StartListening()
    {
    await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 10, true, new Plugin.Geolocator.Abstractions.ListenerSettings
    {
    ActivityType = Plugin.Geolocator.Abstractions.ActivityType.AutomotiveNavigation,
    AllowBackgroundUpdates = true,
    DeferLocationUpdates = true,
    DeferralDistanceMeters = 1,
    DeferralTime = TimeSpan.FromSeconds(1),
    ListenForSignificantChanges = true,
    PauseLocationUpdatesAutomatically = false
    });

    CrossGeolocator.Current.PositionChanged += Current_PositionChanged;
    }

    private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
    {
    Device.BeginInvokeOnMainThread(() =>
    {
    var test = e.Position;
    listenLabel.Text = "Full: Lat: " + test.Latitude.ToString() + " Long: " + test.Longitude.ToString();
    listenLabel.Text += "\n" + $"Time: {test.Timestamp.ToString()}";
    listenLabel.Text += "\n" + $"Heading: {test.Heading.ToString()}";
    listenLabel.Text += "\n" + $"Speed: {test.Speed.ToString()}";
    listenLabel.Text += "\n" + $"Accuracy: {test.Accuracy.ToString()}";
    listenLabel.Text += "\n" + $"Altitude: {test.Altitude.ToString()}";
    listenLabel.Text += "\n" + $"AltitudeAccuracy: {test.AltitudeAccuracy.ToString()}";
    });
    }


    Thanks and Regards

    same with me, do you find any solution?

  • SpaceLordSpaceLord Member ✭✭

    Liem's post seems to be copied from this site, which explains it with a bit better web formatting:

    [disregard: im not allowed to post links here, but to find it just copy paste some of his code into google...]

  • srushteesrushtee Member ✭✭

    @Haskell if You Completed with the tracking part, then please share your code.. will be very thankfull

Sign In or Register to comment.