views:

28

answers:

1

I am trying to create a Google Map with a single coordinate as marker. I use ASP MVC, and the coordinates are saved in the database as a string.

<%: Model.LatLng %>

outputs something like this: 52.425, 4.938

The problem is, Google Maps cannot read this, probably because it is a string. How do I convert the coordinates to something Google Maps can read?

Google map code (just default example)

 var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

 var marker = new google.maps.Marker({
  position: myLatlng, 
  map: map, 
  title:"Hello World!"
}); 

mylatlng needs to be <%: Model.LatLng %> but since its a string it won't work.

+1  A: 

Got the anwser:

var LatLng = "<%: Model.LatLng %>";

    var latlngparts = LatLng.split(",");
    var latlng = new google.maps.LatLng(parseFloat(latlngparts[0]), parseFloat(latlngparts[1]));
Prd