+ Reply to Thread
Results 1 to 16 of 16

Longitude/Latitude wrongly read from XML

  1. #1
    Registered User
    Join Date
    12-18-2019
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office 365
    Posts
    5

    Longitude/Latitude wrongly read from XML

    I cannot seem to figure this out.
    I have an Excel sheet to calculate automatically the driving distance between to addresses. I do this using the Bing Maps API. A URL is filled in with the address and this will give back another URL which is then converted to XML. I then pull the longitude and latitude out of this XML using FILTERXML. In a similar way I can get an XML with the driving distance and driving time between two addresses. And this is where it goes wrong. Somehow, when the distance is small, the distance is displayed correctly, for example 3.91 km. But when the number of decimals is larger than 2, Excel 'converts' for example 67.698 to 67698. See the attached Excel file and a screenshot on how the data is displayed right now.

    I tried by changing the format (text, custom, etc.), but that does not work.

    Similar the reading/conversion of latitude and longitude is not working properly, but there I found a way to solve that, but it is not a beautiful solution in my opinion.

    How can I make Excel show the data it reads from an XML correctly?
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by lonnebol; 12-16-2021 at 08:32 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Longitude/Latitude wrongly read from XML

    Welcome to the forum.

    You've not told us the formula you are using to calculate the distances. Please add this to your sample workbook and post again. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Longitude/Latitude wrongly read from XML

    Try this:

    =--TRIM(LEFT(SUBSTITUTE(MID(T3,FIND("TravelDistance",T3)+15,10),"<",REPT(" ",99)),99))
    Attached Files Attached Files
    Last edited by AliGW; 12-16-2021 at 09:07 AM.

  4. #4
    Registered User
    Join Date
    12-18-2019
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Longitude/Latitude wrongly read from XML

    Quote Originally Posted by AliGW View Post
    Welcome to the forum.

    You've not told us the formula you are using to calculate the distances. Please add this to your sample workbook and post again. Thanks.
    Thank you!

    I do not calculate the distance. This is done online by giving in the locations (latitude and longitude). The URL gives back the XML with the data. I can't post the formula for it in the Excel, because of a personal API key. Sorry for that.



    Quote Originally Posted by AliGW View Post
    Try this:

    =--TRIM(LEFT(SUBSTITUTE(MID(T3,FIND("TravelDistance",T3)+15,10),"<",REPT(" ",99)),99))
    I tried to add it to my sheet, but it gives me #VALUE on the two decimal values and the other values are shown like before (e.g. 67698 instead of 67.698). Same thing happens when I paste other data into your workbook.

    What is really happening here? Why is Excel not giving me back the value as it is in the XML?
    Attached Images Attached Images

  5. #5
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: Longitude/Latitude wrongly read from XML

    I guess your API Key is in the URL of the Rest API. So, may be you need to edit your first message and remove the attached file.

    On the other hand, the related data can be directly fetched by sending a request to the server by VBA.
    Last edited by Haluk; 12-16-2021 at 09:49 AM.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Longitude/Latitude wrongly read from XML

    As you haven't shown us the filterxml formula you are using it's difficult to tell as
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    It maybe that your system uses the . for the thousand separator, rather than the decimal point.

  7. #7
    Registered User
    Join Date
    12-18-2019
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Longitude/Latitude wrongly read from XML

    Quote Originally Posted by Haluk View Post
    On the other hand, the related data can be directly fetched by sending a request to the server by VBA.
    I was hoping to avoid VBA. I know how to use it, but preferably not.

    Quote Originally Posted by Fluff13 View Post
    As you haven't shown us the filterxml formula you are using it's difficult to tell as
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    It maybe that your system uses the . for the thousand separator, rather than the decimal point.
    That is exactly the formula I am using. See the attached file (updated).

    Is there a way to change what separator is used without setting it on the system? The file should work on every computer.
    Attached Files Attached Files

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Longitude/Latitude wrongly read from XML

    My formula works. Maybe you made a mistake copying doen? Why not provide evidence of it not working (NOT a picture, but a workbook)?

  9. #9
    Registered User
    Join Date
    12-18-2019
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Longitude/Latitude wrongly read from XML

    Quote Originally Posted by AliGW View Post
    My formula works. Maybe you made a mistake copying doen? Why not provide evidence of it not working (NOT a picture, but a workbook)?
    You are right. See the attachment.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Longitude/Latitude wrongly read from XML

    I don't know what you are doing, but it's working fine here.

    If you are copying and pasting, try this:

    =--SPATIES.WISSEN(LINKS(SUBSTITUEREN(DEEL(T3;VIND.ALLES("TravelDistance";T3)+15;10);"<";HERHALING(" ";99));99))

  11. #11
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Longitude/Latitude wrongly read from XML

    As long as all user use the comma as the decimal separator you could use this tweak to Ali's formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: Longitude/Latitude wrongly read from XML

    Can you try Ali's formula, which is edited as below;

    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Longitude/Latitude wrongly read from XML

    In T4 if I use the formula =FILTERXML(T4,"//TravelDistance") I will get 1.77 as text, my decimal separator is comma, if I place an extra zero in the XML text in T4 the formula will give me 1770 as number, as pointed by Fluff13.

  14. #14
    Registered User
    Join Date
    12-18-2019
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Longitude/Latitude wrongly read from XML

    Quote Originally Posted by Haluk View Post
    Can you try Ali's formula, which is edited as below;

    Please Login or Register  to view this content.
    Yes, that did the trick! Thank you all very much for your help.

  15. #15
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Longitude/Latitude wrongly read from XML

    Quote Originally Posted by Haluk View Post
    Can you try Ali's formula, which is edited as below;
    Please Login or Register  to view this content.
    Using Ali's formula in T4 I got 1,77 as number to my comma decimal separator system, the correct answer.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Longitude/Latitude wrongly read from XML

    Quote Originally Posted by lonnebol View Post
    Yes, that did the trick! Thank you all very much for your help.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sort by Latitude and Longitude
    By mikey.snodgrass in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-03-2020, 09:28 PM
  2. Latitude/longitude computation?
    By Hambone70 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-27-2014, 12:30 PM
  3. Distance between latitude and longitude
    By fazna ali in forum Excel General
    Replies: 2
    Last Post: 11-06-2012, 05:03 AM
  4. Latitude & Longitude processing help please
    By Pilot_Greg in forum Excel General
    Replies: 11
    Last Post: 12-14-2009, 03:31 PM
  5. MGRS to Longitude/Latitude
    By ajocius in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2009, 11:26 AM
  6. [SOLVED] formula for longitude/latitude
    By Leo in forum Excel General
    Replies: 2
    Last Post: 06-03-2005, 02:05 PM
  7. [SOLVED] Help with Latitude and Longitude.
    By LadiFireBug in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 01-22-2005, 05:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1