简体   繁体   中英

Google Maps API 3, c# MVC5

Hello i have a little problem with latlng class.

When i use it like this:

position: new google.maps.LatLng(51.172414, 17.115294)

marker is in correct position.

But when i want to do that like this:

position: new google.maps.LatLng(@Model[0].latitude, @Model[0].longitude),

there is syntax error on comma and last bracket, and marker doesn't show. Browser debugger doesn't show any problems with js.

latitude and longitude are decimal. Is the reason that they have to much of numbers after comma? If yes , then it should be some errors in js, no syntax error in view.

Any idea what can be wrong? Or how to use own data from model in this class?

The problem was in separator. In DB there was comma, in VS there was point. But in razor in js there was comma again. I solved it like that.

var latit = @Model[0].latitude.ToString().Replace(',','.');
var longit = @Model[0].longitude.ToString().Replace(',','.');            
var marker = new google.maps.Marker({               
    position: new google.maps.LatLng(latit, longit),
    map: map,
    title: '@Html.Raw(Model[0].name)',
    html: '<img src="/Img/'+@Model[0].id+ '_0.jpg" width="250px" height="250px">'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM