Plotting pushpins based on the French coordinate format

Balasaheb Molawade 136 Reputation points
2024-05-28T17:09:35.8633333+00:00

Hi,

We have developed an application using Bing Maps to plot pushpins, and it works fine in English. However, when we change the PC language to French, the latitude/longitude format changes, replacing '.' with ','. This causes the pushpin plotting to fail. Is there a way to resolve this issue.

Thanks!

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
631 questions
{count} votes

1 answer

Sort by: Most helpful
  1. rbrundritt 16,066 Reputation points Microsoft Employee
    2024-05-28T19:17:07.2233333+00:00

    I'm assuming you using JavaScript in a browser and have the latitude/longitude values and are trying to create a string like "latitude, longitude" and want the numbers to use periods for decimal places. As you likely know some cultures use a comma as a decimal place instead. If you simply convert a number to a string in JavaScript it will be formatted based on the culture setting of the browser/device. For example:

    var latitude = 45.001;
    var longitude = -110.001;
    
    var coordString = latitude + ', ' + longitude;
    
    //The coordString value could be "45.001, -110.001" or "45,001, -110,001" depending on culture setting.
    

    To better handle this and force the numbers to use a period for a decimal place, you can use the toLocaleString function and set the culture to en-US.

    var latitude = 45.001;
    var longitude = -110.001;
    
    var coordString = latitude.toLocaleString('en-US') + ', ' + longitude.toLocaleString('en-US');
    
    //The coordString value would only be "45.001, -110.001" regardless of the browsers culture setting.