Razor的谷歌地图
Google Maps from Razor
如何从另一个Razor获取谷歌地图
大家好,我正在努力解决这个问题。。。谷歌地图Javascript在Create.cshtml中,问题在Index.chtml.中
"索引"按钮将Create.cshtml调用为Modal Boostrap。
如何从Create.cshtml.获取Index.chtml
Modal工作正常,但谷歌地图不起作用。
创建.cshtml
<div class="modal fade" id="myModal" role="dialog">
<!-- 'has-error' class has been added on parent form-group div -->
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Create</h4>
</div>
<div class="modal-body">
<div class="form-group">
@Html.LabelFor(m => m.GoogleMaps, new { @class = "col-xs-3 control-label" })
<div class="col-xs-5">
@Html.TextBoxFor(m => m.GoogleMaps, new { @id = "pac-input", @class = "controls", placeholder = "Search" })
<div id="map" style="width:500px;height:380px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
Javascript
function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: { lat: -33.8688, lng: 151.2195 },
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function () {
searchBox.setBounds(map.getBounds());
});
var markers = [];
// [START region_getplaces]
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function () {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
// Clear out the old markers.
markers.forEach(function (marker) {
marker.setMap(null);
});
markers = [];
// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function (place) {
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
// Create a marker for each place.
markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
// [END region_getplaces]
}
<script src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxxxxxxx&libraries=places&callback=initAutocomplete"
async defer></script>
Index.cshtml
<div class="pull-right col-lg-1">
<a class="btn btn-success" onclick="OpenCreatePopup()">
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
<div id="DivToAppendPartialView"></div>
<script>
function OpenCreatePopup() {
$.ajaxSetup({ cache: false });
$('#DivToAppendPartialView').load("/Account/Create", function () {
$('#myModal').modal({
keyboard: true
}, 'show');
});
return false;
};
</script>
问题是没有在模式引导中显示谷歌地图。
帮帮我!
我找到了一个解决方案!
.pac-container {
z-index: 100000;
}
谷歌地图在模态助推器工作!
相关文章:
- 谷歌地图固定位置覆盖
- 不显示带有本地json文件数据的谷歌地图脚本
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 谷歌地图标记不会显示
- 无法在JS中显示谷歌地图
- 科尔多瓦页面类应用程序中的多个谷歌地图
- 需要帮助谷歌地图方向面板在FancyBox中显示
- 在谷歌地图上获取事件的x,y坐标
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 模拟谷歌地图中的点击
- 如何知道哪个标记被谷歌地图点击了
- 谷歌地图JS API+JSON-多个标记没有显示
- 缓存谷歌地图数据
- 谷歌地图劫持了iphone's滚动(触摸事件)-如何恢复
- 在谷歌地图上绘制位置数据库
- 标记的实时更新,无需加载页面谷歌地图API V3
- 我如何使用JavaScript在Razor谷歌地图API
- MVC4/Razor与谷歌地图
- ASP.NET MVC4 Razor in Javascript.谷歌地图未加载
- Razor的谷歌地图