javascript - Razor Syntax not working as I expected -
i have on 136 locations latitude , longitude , trying create, essentially, 136 map markers on map using java script, razor , c#. issue is, piece of javascript in razor not showing , curious if doing correctly.
var mapmarker; @{ ienumerable<ufa.location.core.location> location = ufalocation___front.helpers.queryhelper.queryhelper.getalllocations(); foreach(var loc in location){ <text> mapmarker = new google.maps.marker({ position: new google.maps.latlng(@loc.latitude, @loc.longitude), map: map, title: "hello world!" }); </text> } }
i loop through locations , latitude , longtitude, issue is, markers don't show because piece of javascript in each, doesn't exist.
full script bellow:
function success(position) { var s = document.queryselector('#status'); if (s.classname == 'success') { // not sure why we're hitting twice in ff, think it's cached result coming return; } s.innerhtml = "found you!"; s.classname = 'label label-success'; var latlng = new google.maps.latlng(position.coords.latitude, position.coords.longitude); var directionsservice = new google.maps.directionsservice(); var directionsdisplay = new google.maps.directionsrenderer(); var map = new google.maps.map(document.getelementbyid('map'), { zoom: 15, center: latlng, maptypecontrol: false, navigationcontroloptions: { style: google.maps.navigationcontrolstyle.small }, maptypeid: google.maps.maptypeid.roadmap }); var marker = new google.maps.marker({ position: latlng, map: map, title: "you here! (at least within " + position.coords.accuracy + " meter radius)" }); var mapmarker; @{ ienumerable<ufa.location.core.location> location = ufalocation___front.helpers.queryhelper.queryhelper.getalllocations(); foreach(var loc in location){ <text> mapmarker = new google.maps.marker({ position: new google.maps.latlng(@loc.latitude, @loc.longitude), map: map, title: "hello world!" }); </text> } } var samplemarker = new google.maps.marker({ position: new google.maps.latlng(51.379, -113.53), map: map, title: "hello world!" }); directionsdisplay.setmap(map); var request = { origin: latlng, destination: '304 304 26th ave sw calgary alberta', travelmode: google.maps.directionstravelmode.driving }; directionsservice.route(request, function (response, status) { if (status == google.maps.directionsstatus.ok) { directionsdisplay.setdirections(response); } }); } function error(msg) { var s = document.queryselector('#status'); s.innerhtml = typeof msg == 'string' ? msg : "failed"; s.classname = 'alert alert-error'; // console.log(arguments); } if (navigator.geolocation) { navigator.geolocation.getcurrentposition(success, error); } else { error('not supported'); }
Comments
Post a Comment