Pointers 如何在<;中添加图像;圆圈>;标签
我正在使用谷歌地图,我想把图像放到Pointers 如何在<;中添加图像;圆圈>;标签,pointers,dictionary,Pointers,Dictionary,我正在使用谷歌地图,我想把图像放到标签中。所以请指导我如何在这部分添加图像 我在下面提到了代码。请审阅并回复 假设这是您所指的Google Maps Javascript API(而不是静态地图等其他接口),则需要创建Google.Maps.Marker对象 使用Google提供的作为参考点,您需要为要添加到地图中的每个图像创建以下内容的实例。下面的示例假设您创建了一个google.maps.Map对象,并将其分配给名为Map的javascript变量 var location = new g
标签中。所以请指导我如何在这部分添加图像
我在下面提到了代码。请审阅并回复
假设这是您所指的Google Maps Javascript API(而不是静态地图等其他接口),则需要创建
Google.Maps.Marker
对象
使用Google提供的作为参考点,您需要为要添加到地图中的每个图像创建以下内容的实例。下面的示例假设您创建了一个google.maps.Map
对象,并将其分配给名为Map
的javascript变量
var location = new google.maps.LatLng( -0.127985, 51.507877 ) ;
var marker = new google.maps.Marker( {
position: location,
icon: "https://example.com/images/myImage.png",
map: map
} ) ;
如您所见,google.maps.Marker
对象需要一个指向您的图像和lat的url,只要是google.maps.LatLng
对象
[编辑]
我只是想给你举个简单的例子。这可能不完全是你想要的,例如,要绘制的项目列表等,但它应该让你对在谷歌地图上放置图像有一个公平的理解,并作为你自己进行更改的基础
<html>
<head>
<style>
#map-here {
width: 400px ;
height: 400px ;
border-radius: 3px ;
}
</style>
</head>
<body>
<div id="map-here"></div>
<script>
function wrapper() {
addMapWithMarker( {
'coords': [ 51.507877, -0.127985 ],
'image': 'https://maps.google.com/mapfiles/kml/shapes/info-i_maps.png',
}, 'map-here' ) ;
function addMapWithMarker( args, id ) {
var map = new google.maps.Map(
document.getElementById( id ), {
zoom: 16,
mapTypeId: google.maps.MapTypeId.TERRAIN,
disableDefaultUI: true,
zoomControl: true,
mapTypeControl: true,
scaleControl: false,
streetViewControl: false,
rotateControl: false,
fullscreenControl: false,
center: { lat: args.coords[0], lng: args.coords[1] },
}
) ;
var infoMarker = new google.maps.Marker( {
position: { lat: args.coords[0], lng: args.coords[1] },
icon: args.image,
map: map,
title: "Lord Nelson",
} );
}
}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=<api-key>&libraries=visualization&callback=wrapper"></script>
</body>
</html>
#地图在这里{
宽度:400px;
高度:400px;
边界半径:3px;
}
函数包装器(){
addMapWithMarker({
“coords”:[51.507877,-0.127985],
'图像':'https://maps.google.com/mapfiles/kml/shapes/info-i_maps.png',
}“此处地图”);
函数addMapWithMarker(参数,id){
var map=new google.maps.map(
document.getElementById(id){
缩放:16,
mapTypeId:google.maps.mapTypeId.TERRAIN,
disableDefaultUI:true,
动物控制:对,
mapTypeControl:true,
scaleControl:false,
街景控制:错误,
旋转控制:错误,
全屏控制:错误,
中心:{lat:args.coords[0],lng:args.coords[1]},
}
) ;
var infoMarker=新的google.maps.Marker({
位置:{lat:args.coords[0],lng:args.coords[1]},
图标:args.image,
地图:地图,
标题:“纳尔逊勋爵”,
} );
}
}
用API密钥替换
[结束编辑]如果您想检查我的代码,我可以发送它。。但根据您的示例,它不起作用。您想检查html文件或js配置文件吗?如果可能,请提供url?JS Fiddle还是类似的?我编辑了你的消息,让它看起来像你想要的样子。如果这不是你的意思,请随意回退。