Javascript 谷歌地图正在加载页面,只显示地图框,但不显示';我什么也看不出来
我正在尝试在Lat.和Long的基础上实现谷歌地图。我已经为此编写了以下代码Javascript 谷歌地图正在加载页面,只显示地图框,但不显示';我什么也看不出来,javascript,jquery,html,asp.net,google-maps,Javascript,Jquery,Html,Asp.net,Google Maps,我正在尝试在Lat.和Long的基础上实现谷歌地图。我已经为此编写了以下代码 <script> function geoFindMe() { function success(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; var url = 'https://maps.googl
<script>
function geoFindMe() {
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=false';
$.ajax({
url: url, dataType: "json", async: false, success: function (result) {
if (result.results) {
$('[id$=txLocation]').val(result.results[0].address_components[7].long_name);
}
}
});
initMap(latitude, longitude);
}
function error() {
var latLong;
$.getJSON("https://ipinfo.io", function (ipinfo) {
console.log("Found location [" + ipinfo.loc + "] by ipinfo.io");
latLong = ipinfo.loc.split(",");
var url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + latLong[0] + ',' + latLong[1] + '&sensor=false';
// var URL1 = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&key=AIzaSyAcFUUXsJBxElbLTx4cNFTGFIsmwf5PlSo'
$.ajax({
url: url, dataType: "json", async: false, success: function (result) {
if (result.results) {
$('[id$=txLocation]').val(result.results[0].address_components[7].long_name);
}
}
});
initMap(latLong[0], latLong[1]);
});
}
navigator.geolocation.getCurrentPosition(success, error);
}
function initMap(Lat, lang) {
var myLatlng = { lat: Lat, lng: lang };
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 17,
center: myLatlng
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
函数geoFindMe(){
功能成功(职位){
变量纬度=位置坐标纬度;
var经度=position.coords.longitude;
var url='1〕https://maps.googleapis.com/maps/api/geocode/json?latlng=“+纬度+”、“+经度+”&传感器=假”;
$.ajax({
url:url,数据类型:“json”,异步:false,成功:函数(结果){
if(result.results){
$('[id$=txLocation]').val(result.results[0]。地址\组件[7]。长\名称);
}
}
});
初始地图(纬度、经度);
}
函数错误(){
var latLong;
$.getJSON(“https://ipinfo.io,函数(ipinfo){
log(“通过ipinfo.io找到位置[“+ipinfo.loc+””);
latLong=ipinfo.loc.split(“,”);
var url='1〕https://maps.googleapis.com/maps/api/geocode/json?latlng=“+latLong[0]+”、“+latLong[1]+”&传感器=false”;
//var URL1='1〕https://maps.googleapis.com/maps/api/geocode/json?latlng=“+纬度+”、“+经度+”&key=AIzaSyAcFUUXsJBxElbLTx4cNFTGFIsmwf5PlSo”
$.ajax({
url:url,数据类型:“json”,异步:false,成功:函数(结果){
if(result.results){
$('[id$=txLocation]').val(result.results[0]。地址\组件[7]。长\名称);
}
}
});
initMap(latLong[0],latLong[1]);
});
}
navigator.geolocation.getCurrentPosition(成功,错误);
}
函数initMap(Lat,lang){
var mylatng={lat:lat,lng:lang};
var map=new google.maps.map(document.getElementById('map'){
缩放:17,
中心:myLatlng
});
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“单击以缩放”
});
map.addListener('center\u changed',function(){
//地图中心更改3秒后,平移回地图中心
//马克。
setTimeout(函数(){
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click',函数(){
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
它正在加载,如以下屏幕截图所示:
当我按下F12键时,它开始工作并显示实际地图
请帮帮我。告诉我我做错了什么
提前感谢。检查控制台中的消息…@lonut控制台中没有错误。。请将您的全部代码发布到一个工作代码段中或创建一个。现在我甚至不知道您何时或如何调用
geoFindMe
函数。我发布了所有代码。。就是这样..只想添加脚本引用如果你检查我在上面的评论中发布的脚本引用,那么你可以得到该方法正被用作回调函数