Yiy*_*hen 2 javascript geometry google-maps-api-3 asp.net-mvc-5
我正在尝试在MVC 5项目中显示带有标记和圆圈的地图.地图显示标记,但在圆圈方法a上获取错误setRadius:不是数字.
这里的代码:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
$(document).ready(function () {
initialize();
});
function initialize() {
var myLat = '@Model.Lat'.replace(',', '.').replace(' ', '');
var myLong = '@Model.Lon'.replace(',', '.').replace(' ', '');
var rad = '@Model.Acc'.replace(',', '.').replace(' ', '');
var center = new google.maps.LatLng(myLat, myLong); // LatLng of center point of circle
var mapOptions = {
center: center,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
// create a marker
var marker = new google.maps.Marker({
position: center,
map: map,
title: 'My Place'
});
var options = {
strokeColor: '#0000FF',
strokeOpacity: 1.0,
strokeWeight: 1,
fillColor: '#3366FF',
fillOpacity: 0.5,
map: map,
center: center,
radius: rad
};
circle = new google.maps.Circle(options);
}
</script>
<br />
<div id="map_canvas" style="width:100%; height:480px;">
</div>
Run Code Online (Sandbox Code Playgroud)
我用变量rad显示了变量rad,值为10.5,如果我手动将选项半径设置为10.5就可以了.
问题是什么?
发现了这个问题.我换了
radius: rad
Run Code Online (Sandbox Code Playgroud)
同
radius: parseFloat(rad)
Run Code Online (Sandbox Code Playgroud)
希望也帮助别人.