我想使用Geo位置,但是没有定义google地图。代码如下:
<div id="map_canvas" style="width: 100%; height: 100%"></div>
API代码
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAV8AiebjdcoS-Ratewz-HDkFt7XCq3zOM&libraries=places&callback=initMap"></script>
Scrpirt
$(document).ready(function () {
$('#doctorlocation').goMap({
maptype: 'ROADMAP',
latitude: 40.760651,
longitude: -73.930635,
zoom: 6,
scaleControl: true,
scrollwheel: false,
markers: [
{
latitude: 40.716818, longitude: -73.983164, group: 'doctor', icon: 'http://medical.vanuston.com/images/map/doctor.png', html: {
content: 'Lorem ipsum dolor sit amet.<br /><a href="company-page.html">Read More</a>'
}
}
]
});
});
答案 0 :(得分:1)
您正在使用$.goMap()。请仔细阅读。
并且div也是错误的。 而不是
<div id="map_canvas" style="width: 100%; height: 100%"></div>
它将是
<div id="doctorlocation"></div>
,id
在初始化<{p>}中为doctorlocation
$(function() {
$('#doctorlocation').goMap({
maptype: 'ROADMAP',
latitude: 40.760651,
longitude: -73.930635,
zoom: 6,
scaleControl: true,
scrollwheel: false,
markers: [{
latitude: 40.716818,
longitude: -73.983164,
group: 'doctor',
icon: 'http://medical.vanuston.com/images/map/doctor.png',
html: {
content: 'Lorem ipsum dolor sit amet.<br /><a href="company-page.html">Read More</a>'
}
}]
});
});
#doctorlocation {
width: 700px;
height: 400px;
}
<div id="doctorlocation"></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=AIzaSyAV8AiebjdcoS-Ratewz-HDkFt7XCq3zOM&libraries=places"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.pittss.lv/jquery/gomap/js/jquery.gomap-1.3.3.min.js"></script>
答案 1 :(得分:0)
该错误只能由以下三种情况之一引起:
1) Your JavaScript file is not being properly loaded into your page
2) You have a botched version of jQuery. This could happen because someone edited the core file, or a plugin may have overwritten the $ variable.
3) You have JavaScript running before the page is fully loaded, and as such, before jQuery is fully loaded.
将jquery.js放在脚本标记之前,它会起作用;)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/script.js"></script>