Javascript 来自Razor的谷歌地图
如何从另一台剃须刀上获取谷歌地图? 各位好,, 我正在努力解决这个问题。。。 Google将Javascript映射到Create.cshtml中,问题出在Index.cshtml中 索引按钮将Create.cshtml调用为一个模式Boostrap 如何从Create.cshtml获取Index.cshtml Modal工作正常,但谷歌地图不工作 Create.cshtmlJavascript 来自Razor的谷歌地图,javascript,google-maps,asp.net-mvc-5,bootstrap-modal,Javascript,Google Maps,Asp.net Mvc 5,Bootstrap Modal,如何从另一台剃须刀上获取谷歌地图? 各位好,, 我正在努力解决这个问题。。。 Google将Javascript映射到Create.cshtml中,问题出在Index.cshtml中 索引按钮将Create.cshtml调用为一个模式Boostrap 如何从Create.cshtml获取Index.cshtml Modal工作正常,但谷歌地图不工作 Create.cshtml &时代; 创造 @LabelFor(m=>m.GoogleMaps,新的{@class=“col-xs-3控制标签”}
&时代;
创造
@LabelFor(m=>m.GoogleMaps,新的{@class=“col-xs-3控制标签”})
@TextBoxFor(m=>m.GoogleMaps,新的{@id=“pac-input”,@class=“controls”,placeholder=“Search”})
Javascript
函数initAutocomplete(){
var map=new google.maps.map(document.getElementById('map'){
中心:{lat:-33.8688,lng:151.2195},
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
//创建搜索框并将其链接到UI元素。
var input=document.getElementById('pac-input');
var searchBox=newgoogle.maps.places.searchBox(输入);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(输入);
//将搜索框结果偏向当前地图的视口。
map.addListener('bounds_changed',function(){
searchBox.setBounds(map.getBounds());
});
var标记=[];
//[开始区域\u getplaces]
//侦听用户选择预测并检索时激发的事件
//关于那个地方的更多细节。
searchBox.addListener('places\u changed',函数(){
var places=searchBox.getPlaces();
如果(places.length==0){
返回;
}
//清除旧的标记。
markers.forEach(函数(marker){
marker.setMap(空);
});
标记=[];
//对于每个位置,获取图标、名称和位置。
var bounds=new google.maps.LatLngBounds();
地点。forEach(功能(地点){
变量图标={
url:place.icon,
大小:新谷歌地图大小(71,71),
来源:新google.maps.Point(0,0),
主播:新google.maps.Point(17,34),
scaledSize:new google.maps.Size(25,25)
};
//为每个地方创建一个标记。
markers.push(新的google.maps.Marker)({
地图:地图,
图标:图标,
标题:place.name,
位置:place.geometry.location
}));
if(place.geometry.viewport){
//只有地理代码具有视口。
联合(place.geometry.viewport);
}否则{
扩展(place.geometry.location);
}
});
映射边界(bounds);
});
//[结束区域\u getplaces]
}
Index.cshtml
函数OpenCreatePopup(){
$.ajaxSetup({cache:false});
$('#DivToAppendPartialView')。加载(“/Account/Create”,函数(){
$(“#myModal”).modal({
键盘:正确
}"show";;
});
返回false;
};
问题是在模式引导中不显示谷歌地图
救救我 我找到了解决办法
.pac-container {
z-index: 100000;
}
谷歌地图在模态boostrap工作
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>
<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;
}