在我们的网络应用程序中,我们有window显示我们分会的位置。是否工作正常,除了标记窗口没有显示。点击产生可怕的java脚本错误“ TypeError:a.lat不是函数”。
看看我意识到的这类问题的其他答案,坐标必须是google.maps.LatLng对象或文字。我几乎确信我遵守了这个:
var map = null;
// Call this function when the page has been loaded
function initialize()
{
if (arguments.callee.done) return;
arguments.callee.done = true;
var
coord = { lat: 49.87216, lng: 8.63064 },
mapOptions = {
center: coord,
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: 1,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
scaleControl: 1,
scaleControlOptions: {style: google.maps.ScaleControlStyle.DEFAULT, position: google.maps.ControlPosition.BOTTOM_RIGHT},
navigationControl: 1,
navigationControlOptions: {style: google.maps.ZoomControlStyle.ZOOM_PAN, position: google.maps.ControlPosition.RIGHT},
position: google.maps.ControlPosition.BOTTOM_LEFT
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
marker = new google.maps.Marker({
title: "Fahrradbüro",
position: coord,
map: map
});
kartenFenster = new google.maps.InfoWindow(
{
content: '<div style="text-align: center"><img src="/static/images/images" alt="Fahrradbüro"/><br/>Fahrradbüro<br /></div>'
});
marker.addListener('click', function() {
kartenFenster.open(map, marker);
});
}
但我仍然遇到这个错误。我在这里错过了什么?我甚至尝试过:
var coord = new google.maps.LatLng( 49.87216, 8.63064 );
感谢您的帮助!
答案 0 :(得分:1)
从mapOptions
:
position: google.maps.ControlPosition.BOTTOM_LEFT
API还会尝试访问position
中地图的open()
- 属性(请注意open()
的第一个参数也可能是StreetViewPanorama,它有一个位置属性)导致错误的原因(因为此属性不是LatLng)。
答案 1 :(得分:0)
var map;
// Call this function when the page has been loaded
function initialize()
{
if (arguments.callee.done) return;
arguments.callee.done = true;
var coord = new google.maps.LatLng( 49.87216, 8.63064 );
var mapOptions = {
center: coord,
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: 1,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
scaleControl: 1,
scaleControlOptions: {style: google.maps.ScaleControlStyle.DEFAULT, position: google.maps.ControlPosition.BOTTOM_RIGHT},
navigationControl: 1,
navigationControlOptions: {style: google.maps.ZoomControlStyle.ZOOM_PAN, position: google.maps.ControlPosition.RIGHT},
position: google.maps.ControlPosition.BOTTOM_LEFT
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
marker = new google.maps.Marker({
title: "Fahrradbüro",
position: coord,
map: map
});
kartenFenster = new google.maps.InfoWindow(
{
content: '<div style="text-align: center"><img src="/static/images/images" alt="Fahrradbüro"/><br/>Fahrradbüro<br /></div>'
});
marker.addListener('click', function() {
kartenFenster.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load',initialize);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<div id="map" style="height:300px;width:400px"></div>
请检查片段。我添加了id =“map”的div以及坐标和js的少量更改。