将图像链接到谷歌地图上的标记
我的地图上有一个自定义标记,地图上方有一个图像,我希望单击该图像,将谷歌地图置于自定义标记上,图像链接到。我该如何使用 google api 来做到这一点?我很难弄清楚什么 google api 代码可以做到这一点,有人能给我举个例子吗?
我正在尝试将其添加到 companyimage 变量
<!DOCTYPE html> <html> <head>
<LINK REL=StyleSheet HREF="styles.css" TYPE="text/css" MEDIA=screen>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(39.346246,-76.624446);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Høgenhaug</h1>'+
'<div id="bodyContent">'+
'<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var companyImage = new google.maps.MarkerImage('images/Loyola.png',
new google.maps.Size(100,50),
new google.maps.Point(0,0),
new google.maps.Point(50,50)
);
var companyShadow = new google.maps.MarkerImage('images/logo_shadow.png',
new google.maps.Size(130,50),
new google.maps.Point(0,0),
new google.maps.Point(65, 50));
var companyPos = new google.maps.LatLng(39.346246,-76.624446);
var companyMarker = new google.maps.Marker({
position: companyPos,
map: map,
icon: companyImage,
shadow: companyShadow,
title:"School",
zIndex: 3});
var trainImage = new google.maps.MarkerImage('images/barlandmark.png',
new google.maps.Size(70,70),
new google.maps.Point(0,0),
new google.maps.Point(50,50)
);
var trainShadow = new google.maps.MarkerImage('images/train_shadow.png',
new google.maps.Size(70,50),
new google.maps.Point(0,0),
new google.maps.Point(60, 50)
);
var trainPos = new google.maps.LatLng(39.363136,-76.609841);
var trainMarker = new google.maps.Marker({
position: trainPos,
map: map,
icon: trainImage,
shadow: trainShadow,
title:"Train Station",
zIndex: 2
});
}
I have a custom marker on my map, and an image above the maps, which I would like to have on click, center the google map on the custom marker, the image is linked to. How would I do that with google api? I am terrible with figuring out what google api code could do this, could someone show me an example?
I am trying to add it to the companyimage variable
<!DOCTYPE html> <html> <head>
<LINK REL=StyleSheet HREF="styles.css" TYPE="text/css" MEDIA=screen>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(39.346246,-76.624446);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Høgenhaug</h1>'+
'<div id="bodyContent">'+
'<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var companyImage = new google.maps.MarkerImage('images/Loyola.png',
new google.maps.Size(100,50),
new google.maps.Point(0,0),
new google.maps.Point(50,50)
);
var companyShadow = new google.maps.MarkerImage('images/logo_shadow.png',
new google.maps.Size(130,50),
new google.maps.Point(0,0),
new google.maps.Point(65, 50));
var companyPos = new google.maps.LatLng(39.346246,-76.624446);
var companyMarker = new google.maps.Marker({
position: companyPos,
map: map,
icon: companyImage,
shadow: companyShadow,
title:"School",
zIndex: 3});
var trainImage = new google.maps.MarkerImage('images/barlandmark.png',
new google.maps.Size(70,70),
new google.maps.Point(0,0),
new google.maps.Point(50,50)
);
var trainShadow = new google.maps.MarkerImage('images/train_shadow.png',
new google.maps.Size(70,50),
new google.maps.Point(0,0),
new google.maps.Point(60, 50)
);
var trainPos = new google.maps.LatLng(39.363136,-76.609841);
var trainMarker = new google.maps.Marker({
position: trainPos,
map: map,
icon: trainImage,
shadow: trainShadow,
title:"Train Station",
zIndex: 2
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 jquery 和 google API V-3,您可以使用
将 var YOURMAP 指向地图以及纬度和经度,它将以该点为中心并根据需要调整大小。
with jquery and google API V-3 you can use
point the var YOURMAP to the map and the lat and lng an it will center on the point and resize if needed.
http://code.google.com/intl /zh/apis/maps/documentation/javascript/reference.html#Map
http://code.google.com/intl/en/apis/maps/documentation/javascript/reference.html#Map
您需要执行以下操作:
或者
并确保更改图像的 id 以匹配选择器。
确保将地图替换为您创建的地图的名称。
将标记替换为您创建的标记的名称。
如果使用第一个示例,请将纬度/经度替换为正确的位置。
API V3 的 Google 地图事件
http://code.google.com/apis /maps/documentation/javascript/events.html
Youd need to do something like this:
Or
And make sure you change the id of your image to match the selector.
Make sure you replace map with the name of your created map.
Replace marker with the name of your created marker.
And if using the first example, replace lat/lng with the correct positions.
Google Maps Events for API V3
http://code.google.com/apis/maps/documentation/javascript/events.html