Convert LatLng to (x, y) coordinates












-2














I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.



But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.



I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.



Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.










share|improve this question


















  • 3




    developers.google.com/maps/documentation/javascript/reference/…
    – MrUpsidown
    Nov 21 '18 at 9:44
















-2














I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.



But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.



I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.



Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.










share|improve this question


















  • 3




    developers.google.com/maps/documentation/javascript/reference/…
    – MrUpsidown
    Nov 21 '18 at 9:44














-2












-2








-2


0





I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.



But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.



I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.



Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.










share|improve this question













I'm working on Google maps which will show multiple vehicles. I've two points(one point which will be the old position and other will be the present position) this positioning system will help write an equation of a line passing through these two points. Which might intersect with other line and inform me about the probability of collision.



But the problem is that I'm fetching the coordinates from the GPS module and it will give the location in Latitude and Longitude format.



I'll need x, y coordinates for this writing the equation of the line passing through them. I've already explored most of the method in different web pages, but the problem is that they will ask for some screen size(or map bounds) which are kind of not compatible with my type of method.



Questions: What is the method to convert Latitude and Longitude to (x, y) coordinates, just like if we see from the space and earth was flat and taking Gulf of Guinea (Lat: 0°, Lon: 0°) as the origin.







google-maps google-maps-api-3 maps latitude-longitude






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 9:30









Arshdeep Singh

398




398








  • 3




    developers.google.com/maps/documentation/javascript/reference/…
    – MrUpsidown
    Nov 21 '18 at 9:44














  • 3




    developers.google.com/maps/documentation/javascript/reference/…
    – MrUpsidown
    Nov 21 '18 at 9:44








3




3




developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44




developers.google.com/maps/documentation/javascript/reference/…
– MrUpsidown
Nov 21 '18 at 9:44












2 Answers
2






active

oldest

votes


















0















  1. If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.


  2. If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.



For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.



As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
1) (0.0km 0.0km)
2) (21.86km 11.1km)



X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km



Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km



If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.






share|improve this answer





















  • He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
    – lusitanica
    Nov 21 '18 at 11:25












  • Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
    – Alexey Kornev
    Nov 21 '18 at 11:36










  • Yup, if they are about to intercept the distance will be really, really small.
    – lusitanica
    Nov 21 '18 at 11:40



















-1














For small distances Pythagoras’ theorem can be used on an equi­rectangular projec­tion:



var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
var y = (φ2-φ1);


Where φ1, λ1= 0 (according to the end of your last paragraph).



Note that you can use x,y as input for your equations, but not to visualize on Google Maps.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408922%2fconvert-latlng-to-x-y-coordinates%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    1. If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.


    2. If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.



    For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.



    As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
    1) (0.0km 0.0km)
    2) (21.86km 11.1km)



    X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km



    Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km



    If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.






    share|improve this answer





















    • He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
      – lusitanica
      Nov 21 '18 at 11:25












    • Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
      – Alexey Kornev
      Nov 21 '18 at 11:36










    • Yup, if they are about to intercept the distance will be really, really small.
      – lusitanica
      Nov 21 '18 at 11:40
















    0















    1. If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.


    2. If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.



    For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.



    As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
    1) (0.0km 0.0km)
    2) (21.86km 11.1km)



    X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km



    Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km



    If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.






    share|improve this answer





















    • He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
      – lusitanica
      Nov 21 '18 at 11:25












    • Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
      – Alexey Kornev
      Nov 21 '18 at 11:36










    • Yup, if they are about to intercept the distance will be really, really small.
      – lusitanica
      Nov 21 '18 at 11:40














    0












    0








    0







    1. If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.


    2. If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.



    For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.



    As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
    1) (0.0km 0.0km)
    2) (21.86km 11.1km)



    X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km



    Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km



    If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.






    share|improve this answer













    1. If your task requires high accuracy you have to use Latitude/Longitude and to solve Great Circle intersection task. The Earth is not flat.


    2. If you can accept existence of some error in your calculations AND all of your vehicles are located in small limited area (up to 100km, although it depends on error you can accept) you may assume this confined area as flat.



    For instance, if one your vehicle is located at N10.0 E10.0, second one is located at N10.1 E10.2, you may choose N10.0 E10.0 as the origin.



    As a result, these two vehicles will have the following (X, Y) coords (it assumes that axis X goes along equator):
    1) (0.0km 0.0km)
    2) (21.86km 11.1km)



    X of second vehicle is (40000km / 360 degrees) * cos(10.0) * (10.2 - 10.0) = 21.86km



    Y of second vehicle is (40000km / 360 degrees) * (10.1 - 10.0) = 11.1km



    If you will try to apply flat line-line intersection for vehicles located in 10 000 km from each other - your calcutions most probably will be incorrect.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 11:20









    Alexey Kornev

    262




    262












    • He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
      – lusitanica
      Nov 21 '18 at 11:25












    • Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
      – Alexey Kornev
      Nov 21 '18 at 11:36










    • Yup, if they are about to intercept the distance will be really, really small.
      – lusitanica
      Nov 21 '18 at 11:40


















    • He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
      – lusitanica
      Nov 21 '18 at 11:25












    • Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
      – Alexey Kornev
      Nov 21 '18 at 11:36










    • Yup, if they are about to intercept the distance will be really, really small.
      – lusitanica
      Nov 21 '18 at 11:40
















    He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
    – lusitanica
    Nov 21 '18 at 11:25






    He's asking for x,y coordinates for an equation he already has. Not to solve the problem on the sphere. The vehicles are presumebly cars.
    – lusitanica
    Nov 21 '18 at 11:25














    Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
    – Alexey Kornev
    Nov 21 '18 at 11:36




    Ok. Author tries to find trajectory intersection actually. If he tries to use trivial line equation like ax + by = c for two distant vehicles the result can be erroneous. However such equation can be used (with some acceptable error) if distance between vehicles is small.
    – Alexey Kornev
    Nov 21 '18 at 11:36












    Yup, if they are about to intercept the distance will be really, really small.
    – lusitanica
    Nov 21 '18 at 11:40




    Yup, if they are about to intercept the distance will be really, really small.
    – lusitanica
    Nov 21 '18 at 11:40













    -1














    For small distances Pythagoras’ theorem can be used on an equi­rectangular projec­tion:



    var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
    var y = (φ2-φ1);


    Where φ1, λ1= 0 (according to the end of your last paragraph).



    Note that you can use x,y as input for your equations, but not to visualize on Google Maps.






    share|improve this answer




























      -1














      For small distances Pythagoras’ theorem can be used on an equi­rectangular projec­tion:



      var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
      var y = (φ2-φ1);


      Where φ1, λ1= 0 (according to the end of your last paragraph).



      Note that you can use x,y as input for your equations, but not to visualize on Google Maps.






      share|improve this answer


























        -1












        -1








        -1






        For small distances Pythagoras’ theorem can be used on an equi­rectangular projec­tion:



        var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
        var y = (φ2-φ1);


        Where φ1, λ1= 0 (according to the end of your last paragraph).



        Note that you can use x,y as input for your equations, but not to visualize on Google Maps.






        share|improve this answer














        For small distances Pythagoras’ theorem can be used on an equi­rectangular projec­tion:



        var x = (λ2-λ1) * Math.cos((φ1+φ2)/2);
        var y = (φ2-φ1);


        Where φ1, λ1= 0 (according to the end of your last paragraph).



        Note that you can use x,y as input for your equations, but not to visualize on Google Maps.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 11:08

























        answered Nov 21 '18 at 10:38









        lusitanica

        45829




        45829






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408922%2fconvert-latlng-to-x-y-coordinates%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen