Split e.location string into variables












1















I am using leaflet watch.position. It returns a value of



LatLng(52.409958, -1.531085)


I need to split is so that



var lat = 52.309958
var lng = -1.5310.85


Maybe I am being thick but I just cant do it? Any suggestion? I have tried split but no joy










share|improve this question




















  • 1





    The thing it returns, is it a string that looks like that?

    – Olian04
    Nov 23 '18 at 18:39











  • Can you post the split that didn't work?

    – PM 77-1
    Nov 23 '18 at 18:40











  • var tosplit = e.latlng; var fields = tosplit.split(','); var lat = fields[0]; var lng = fields[1];

    – larry chambers
    Nov 23 '18 at 18:42











  • The value of e.latlng is ' LatLng(52.409958, -1.531085)' Thats what I need to split

    – larry chambers
    Nov 23 '18 at 18:43











  • See also: leafletjs.com/reference-1.3.4.html#latlng

    – Mark Meyer
    Nov 23 '18 at 18:48
















1















I am using leaflet watch.position. It returns a value of



LatLng(52.409958, -1.531085)


I need to split is so that



var lat = 52.309958
var lng = -1.5310.85


Maybe I am being thick but I just cant do it? Any suggestion? I have tried split but no joy










share|improve this question




















  • 1





    The thing it returns, is it a string that looks like that?

    – Olian04
    Nov 23 '18 at 18:39











  • Can you post the split that didn't work?

    – PM 77-1
    Nov 23 '18 at 18:40











  • var tosplit = e.latlng; var fields = tosplit.split(','); var lat = fields[0]; var lng = fields[1];

    – larry chambers
    Nov 23 '18 at 18:42











  • The value of e.latlng is ' LatLng(52.409958, -1.531085)' Thats what I need to split

    – larry chambers
    Nov 23 '18 at 18:43











  • See also: leafletjs.com/reference-1.3.4.html#latlng

    – Mark Meyer
    Nov 23 '18 at 18:48














1












1








1








I am using leaflet watch.position. It returns a value of



LatLng(52.409958, -1.531085)


I need to split is so that



var lat = 52.309958
var lng = -1.5310.85


Maybe I am being thick but I just cant do it? Any suggestion? I have tried split but no joy










share|improve this question
















I am using leaflet watch.position. It returns a value of



LatLng(52.409958, -1.531085)


I need to split is so that



var lat = 52.309958
var lng = -1.5310.85


Maybe I am being thick but I just cant do it? Any suggestion? I have tried split but no joy







javascript split






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 18:39









PM 77-1

8,852144685




8,852144685










asked Nov 23 '18 at 18:37









larry chamberslarry chambers

1009




1009








  • 1





    The thing it returns, is it a string that looks like that?

    – Olian04
    Nov 23 '18 at 18:39











  • Can you post the split that didn't work?

    – PM 77-1
    Nov 23 '18 at 18:40











  • var tosplit = e.latlng; var fields = tosplit.split(','); var lat = fields[0]; var lng = fields[1];

    – larry chambers
    Nov 23 '18 at 18:42











  • The value of e.latlng is ' LatLng(52.409958, -1.531085)' Thats what I need to split

    – larry chambers
    Nov 23 '18 at 18:43











  • See also: leafletjs.com/reference-1.3.4.html#latlng

    – Mark Meyer
    Nov 23 '18 at 18:48














  • 1





    The thing it returns, is it a string that looks like that?

    – Olian04
    Nov 23 '18 at 18:39











  • Can you post the split that didn't work?

    – PM 77-1
    Nov 23 '18 at 18:40











  • var tosplit = e.latlng; var fields = tosplit.split(','); var lat = fields[0]; var lng = fields[1];

    – larry chambers
    Nov 23 '18 at 18:42











  • The value of e.latlng is ' LatLng(52.409958, -1.531085)' Thats what I need to split

    – larry chambers
    Nov 23 '18 at 18:43











  • See also: leafletjs.com/reference-1.3.4.html#latlng

    – Mark Meyer
    Nov 23 '18 at 18:48








1




1





The thing it returns, is it a string that looks like that?

– Olian04
Nov 23 '18 at 18:39





The thing it returns, is it a string that looks like that?

– Olian04
Nov 23 '18 at 18:39













Can you post the split that didn't work?

– PM 77-1
Nov 23 '18 at 18:40





Can you post the split that didn't work?

– PM 77-1
Nov 23 '18 at 18:40













var tosplit = e.latlng; var fields = tosplit.split(','); var lat = fields[0]; var lng = fields[1];

– larry chambers
Nov 23 '18 at 18:42





var tosplit = e.latlng; var fields = tosplit.split(','); var lat = fields[0]; var lng = fields[1];

– larry chambers
Nov 23 '18 at 18:42













The value of e.latlng is ' LatLng(52.409958, -1.531085)' Thats what I need to split

– larry chambers
Nov 23 '18 at 18:43





The value of e.latlng is ' LatLng(52.409958, -1.531085)' Thats what I need to split

– larry chambers
Nov 23 '18 at 18:43













See also: leafletjs.com/reference-1.3.4.html#latlng

– Mark Meyer
Nov 23 '18 at 18:48





See also: leafletjs.com/reference-1.3.4.html#latlng

– Mark Meyer
Nov 23 '18 at 18:48












2 Answers
2






active

oldest

votes


















3














LatLng has the following properties:




lat Number Latitude in degrees



lng Number Longitude in degrees



alt Number Altitude in meters (optional)




The solution would then be (where obj is the return LatLng object):



const lat = obj.lat;
const lng = obj.lng;


Or even simpler:



const {lat, lng} = obj;





share|improve this answer
























  • Ok, but where do I use this then? I cant just add that.

    – larry chambers
    Nov 23 '18 at 18:45











  • @larrychambers you would have to provide more code for me to give you a more detailed answer. However, you simply use it with the watch.position return value, no?

    – kemicofa
    Nov 23 '18 at 18:46











  • What code shall I provide. When running leaflet in watch mode, it returns a value of e.latlng That value in this case is " LatLng(52.409958, -1.531085)" I just need to split it so that I have the lat and lng stored. Thanks

    – larry chambers
    Nov 23 '18 at 18:52











  • @larrychambers sorry was a bit busy. Do you still need help? If so then simply check if the return result is an instanceof String (which I HIGHLY doubt). If it is (which again I highly doubt) then you'll have to use some regex or a split method to get the different values.

    – kemicofa
    Nov 23 '18 at 19:11













  • Kemicofa, it works with this mate. Are you saying that way doesnt work? var test = e.latlng; const lat = test.lat; const lng = test.lng;

    – larry chambers
    Nov 23 '18 at 19:36



















0














var test = e.latlng;
const lat = test.lat;
const lng = test.lng;





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%2f53451559%2fsplit-e-location-string-into-variables%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









    3














    LatLng has the following properties:




    lat Number Latitude in degrees



    lng Number Longitude in degrees



    alt Number Altitude in meters (optional)




    The solution would then be (where obj is the return LatLng object):



    const lat = obj.lat;
    const lng = obj.lng;


    Or even simpler:



    const {lat, lng} = obj;





    share|improve this answer
























    • Ok, but where do I use this then? I cant just add that.

      – larry chambers
      Nov 23 '18 at 18:45











    • @larrychambers you would have to provide more code for me to give you a more detailed answer. However, you simply use it with the watch.position return value, no?

      – kemicofa
      Nov 23 '18 at 18:46











    • What code shall I provide. When running leaflet in watch mode, it returns a value of e.latlng That value in this case is " LatLng(52.409958, -1.531085)" I just need to split it so that I have the lat and lng stored. Thanks

      – larry chambers
      Nov 23 '18 at 18:52











    • @larrychambers sorry was a bit busy. Do you still need help? If so then simply check if the return result is an instanceof String (which I HIGHLY doubt). If it is (which again I highly doubt) then you'll have to use some regex or a split method to get the different values.

      – kemicofa
      Nov 23 '18 at 19:11













    • Kemicofa, it works with this mate. Are you saying that way doesnt work? var test = e.latlng; const lat = test.lat; const lng = test.lng;

      – larry chambers
      Nov 23 '18 at 19:36
















    3














    LatLng has the following properties:




    lat Number Latitude in degrees



    lng Number Longitude in degrees



    alt Number Altitude in meters (optional)




    The solution would then be (where obj is the return LatLng object):



    const lat = obj.lat;
    const lng = obj.lng;


    Or even simpler:



    const {lat, lng} = obj;





    share|improve this answer
























    • Ok, but where do I use this then? I cant just add that.

      – larry chambers
      Nov 23 '18 at 18:45











    • @larrychambers you would have to provide more code for me to give you a more detailed answer. However, you simply use it with the watch.position return value, no?

      – kemicofa
      Nov 23 '18 at 18:46











    • What code shall I provide. When running leaflet in watch mode, it returns a value of e.latlng That value in this case is " LatLng(52.409958, -1.531085)" I just need to split it so that I have the lat and lng stored. Thanks

      – larry chambers
      Nov 23 '18 at 18:52











    • @larrychambers sorry was a bit busy. Do you still need help? If so then simply check if the return result is an instanceof String (which I HIGHLY doubt). If it is (which again I highly doubt) then you'll have to use some regex or a split method to get the different values.

      – kemicofa
      Nov 23 '18 at 19:11













    • Kemicofa, it works with this mate. Are you saying that way doesnt work? var test = e.latlng; const lat = test.lat; const lng = test.lng;

      – larry chambers
      Nov 23 '18 at 19:36














    3












    3








    3







    LatLng has the following properties:




    lat Number Latitude in degrees



    lng Number Longitude in degrees



    alt Number Altitude in meters (optional)




    The solution would then be (where obj is the return LatLng object):



    const lat = obj.lat;
    const lng = obj.lng;


    Or even simpler:



    const {lat, lng} = obj;





    share|improve this answer













    LatLng has the following properties:




    lat Number Latitude in degrees



    lng Number Longitude in degrees



    alt Number Altitude in meters (optional)




    The solution would then be (where obj is the return LatLng object):



    const lat = obj.lat;
    const lng = obj.lng;


    Or even simpler:



    const {lat, lng} = obj;






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 18:43









    kemicofakemicofa

    9,74543881




    9,74543881













    • Ok, but where do I use this then? I cant just add that.

      – larry chambers
      Nov 23 '18 at 18:45











    • @larrychambers you would have to provide more code for me to give you a more detailed answer. However, you simply use it with the watch.position return value, no?

      – kemicofa
      Nov 23 '18 at 18:46











    • What code shall I provide. When running leaflet in watch mode, it returns a value of e.latlng That value in this case is " LatLng(52.409958, -1.531085)" I just need to split it so that I have the lat and lng stored. Thanks

      – larry chambers
      Nov 23 '18 at 18:52











    • @larrychambers sorry was a bit busy. Do you still need help? If so then simply check if the return result is an instanceof String (which I HIGHLY doubt). If it is (which again I highly doubt) then you'll have to use some regex or a split method to get the different values.

      – kemicofa
      Nov 23 '18 at 19:11













    • Kemicofa, it works with this mate. Are you saying that way doesnt work? var test = e.latlng; const lat = test.lat; const lng = test.lng;

      – larry chambers
      Nov 23 '18 at 19:36



















    • Ok, but where do I use this then? I cant just add that.

      – larry chambers
      Nov 23 '18 at 18:45











    • @larrychambers you would have to provide more code for me to give you a more detailed answer. However, you simply use it with the watch.position return value, no?

      – kemicofa
      Nov 23 '18 at 18:46











    • What code shall I provide. When running leaflet in watch mode, it returns a value of e.latlng That value in this case is " LatLng(52.409958, -1.531085)" I just need to split it so that I have the lat and lng stored. Thanks

      – larry chambers
      Nov 23 '18 at 18:52











    • @larrychambers sorry was a bit busy. Do you still need help? If so then simply check if the return result is an instanceof String (which I HIGHLY doubt). If it is (which again I highly doubt) then you'll have to use some regex or a split method to get the different values.

      – kemicofa
      Nov 23 '18 at 19:11













    • Kemicofa, it works with this mate. Are you saying that way doesnt work? var test = e.latlng; const lat = test.lat; const lng = test.lng;

      – larry chambers
      Nov 23 '18 at 19:36

















    Ok, but where do I use this then? I cant just add that.

    – larry chambers
    Nov 23 '18 at 18:45





    Ok, but where do I use this then? I cant just add that.

    – larry chambers
    Nov 23 '18 at 18:45













    @larrychambers you would have to provide more code for me to give you a more detailed answer. However, you simply use it with the watch.position return value, no?

    – kemicofa
    Nov 23 '18 at 18:46





    @larrychambers you would have to provide more code for me to give you a more detailed answer. However, you simply use it with the watch.position return value, no?

    – kemicofa
    Nov 23 '18 at 18:46













    What code shall I provide. When running leaflet in watch mode, it returns a value of e.latlng That value in this case is " LatLng(52.409958, -1.531085)" I just need to split it so that I have the lat and lng stored. Thanks

    – larry chambers
    Nov 23 '18 at 18:52





    What code shall I provide. When running leaflet in watch mode, it returns a value of e.latlng That value in this case is " LatLng(52.409958, -1.531085)" I just need to split it so that I have the lat and lng stored. Thanks

    – larry chambers
    Nov 23 '18 at 18:52













    @larrychambers sorry was a bit busy. Do you still need help? If so then simply check if the return result is an instanceof String (which I HIGHLY doubt). If it is (which again I highly doubt) then you'll have to use some regex or a split method to get the different values.

    – kemicofa
    Nov 23 '18 at 19:11







    @larrychambers sorry was a bit busy. Do you still need help? If so then simply check if the return result is an instanceof String (which I HIGHLY doubt). If it is (which again I highly doubt) then you'll have to use some regex or a split method to get the different values.

    – kemicofa
    Nov 23 '18 at 19:11















    Kemicofa, it works with this mate. Are you saying that way doesnt work? var test = e.latlng; const lat = test.lat; const lng = test.lng;

    – larry chambers
    Nov 23 '18 at 19:36





    Kemicofa, it works with this mate. Are you saying that way doesnt work? var test = e.latlng; const lat = test.lat; const lng = test.lng;

    – larry chambers
    Nov 23 '18 at 19:36













    0














    var test = e.latlng;
    const lat = test.lat;
    const lng = test.lng;





    share|improve this answer




























      0














      var test = e.latlng;
      const lat = test.lat;
      const lng = test.lng;





      share|improve this answer


























        0












        0








        0







        var test = e.latlng;
        const lat = test.lat;
        const lng = test.lng;





        share|improve this answer













        var test = e.latlng;
        const lat = test.lat;
        const lng = test.lng;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 19:00









        larry chamberslarry chambers

        1009




        1009






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451559%2fsplit-e-location-string-into-variables%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python