I use the following razor code to generate some javascript to produce markers on a Google map.
@foreach(Point point in Model.Points.Take(3))
{
String longitude = point.Longitude.ToString(CultureInfo.InvariantCulture);
String latitude = point.Latitude.ToString(CultureInfo.InvariantCulture);
<text>
var location = new google.maps.LatLng(@(longitude), @(latitude));
bounds.extend(location);
var marker = new google.maps.Marker({
position: location,
map: map
});
</text>
}
In development, this correctly becomes:
var location = new google.maps.LatLng(52.2124273, 5.9545532);
bounds.extend(location);
var marker = new google.maps.Marker({
position: location,
map: map
});
However, on our production server, it becomes:
var location = new google.maps.LatLng(522124273000, 59545532000);
bounds.extend(location);
var marker = new google.maps.Marker({
position: location,
map: map
});
Which is producing just a grey Google map. What is causing this strange ToString
behavior?
edit
The Point class is a custom class, not from a library. Here are the relevant parts:
public class Point
{
private Double latitude;
private Double longitude;
public Double Latitude
{
get
{
return latitude;
}
}
public Double Longitude
{
get
{
return longitude;
}
}
}
JK and AlexC were right, see their comments on my question. The data was coming in wrong from the external API. Setting the global culture to en-US solved the issue.
I only do not understand one thing: I'm using a library which uses JSON.net, everywhere in the documentation it says the parsing is done with InvariantCulture. So I would think the global culture would not make a difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With