添加声音标记的数组 - 谷歌地图的JavaScript [英] adding sound to an array of markers - google map javascript
问题描述
我是新来的,所以我知道我没有任何可信度。我是一个艺术家和新的节目让我明白,如果没有人会借此上。我上起飞的机会,这是一个简单的问题张贴本。 -S
这是code(主要来自谷歌的开发者网站)来创建多个标记。它工作正常,并为每个标记的自定义图标。
点击时(此时只有最后一个标记创建所做的)每个标志应该发挥不同的音频文件。我也想改当音频文件播放的图标。我使用javascript和声音管理器2播放音频 - 但我感兴趣的是什么:
我如何引用每个标记阵列中,这样我可以发挥分配给特定的标记特定的音频文件?
我希望我CSN做这没有XML和数据库。
-Sabine
下面是相关code:
setMarkers(地图,海滩);
}
VAR的沙滩= [
['献身',40.710431,-73.948432,0],
['测试',40.711223,-73.958416,1],
];功能setMarkers(地图,位置){ VAR形象=新google.maps.MarkerImage('biker.png',
//这个标记是20个像素宽32像素高。
新为google.maps.Size(32,32),
//该图片的原点是0,0。
新google.maps.Point(0,0),
//该图片的锚旗杆在0.32的基础。
新google.maps.Point(0,32)
); VAR newimage =新google.maps.MarkerImage('biker_click.png',
//这个标记是20个像素宽32像素高。
新为google.maps.Size(32,32),
//该图片的原点是0,0。
新google.maps.Point(0,0),
//该图片的锚旗杆在0.32的基础。
新google.maps.Point(0,32)
);VAR形状= {
坐标:[1,1,1,20,18,20,18,1],
类型:'聚'
}; 对于(VAR I = 0; I< locations.length;我++){
VAR沙滩=位置[I]
VAR myLatLng =新google.maps.LatLng(海滨[1],海滨[2]);
VAR的标记=新google.maps.Marker({
位置:myLatLng,
地图:地图,
图标:图像,
外形:外形,
标题:海滩[0]
zIndex的:海滨[3] });
}功能markerClick(){
的console.log('点击');
}
google.maps.event.addListener(标记,'点击',markerClick);功能markerClick(){
VAR播放= sm2.toggle('http://mm1.ellieirons.com/wp-content/uploads/2012/03/beeps_bubbles.mp3',真);
如果(打){
this.setIcon(newimage);
}其他{
this.setIcon(图片);
}
}
假设你有网址的数组:
VAR听起来= [http://mm1.ellieirons.com/wp-content/uploads/2012/03/beeps_bubbles.mp3
http://mm1.ellieirons.com/wp-content/uploads/2012/03/beeps_bubbles2.mp3];
那么你可以尝试这样的事:
为(VAR I = 0; I< locations.length;我++){
VAR沙滩=位置[I]
VAR myLatLng =新google.maps.LatLng(海滨[1],海滨[2]);
VAR的标记=新google.maps.Marker({
位置:myLatLng,
地图:地图,
图标:图像,
外形:外形,
标题:海滩[0]
zIndex的:海滩[3]
});
marker.sound =声音[I] //存储标记相关联的声音
google.maps.event.addListener(标记,'点击',markerClick);
}
和修改的处理程序是:
函数markerClick(){
VAR播放= sm2.toggle(this.sound,真);
如果(打){
this.setIcon(newimage);
}其他{
this.setIcon(图片);
}
}
I am new here so I know I don't have any credibility. I am an artist and new to programming so I understand if no one will take this on. I am posting this on the off chance that this is an easy question. -S
This is the code (mostly from the google developer site) to create multiple markers. It works fine and creates a custom icon for each marker. Each marker should play a different audio file when clicked (right now only the last marker created does). I would also like to change the icon when the audio file is playing. I am using javascript and sound manager 2 to play the audio - but what i am interested in is: how do i reference each marker in the array so that i can play the specific audio file assigned to that specific marker?
I am hoping i csn do this without XML and a database. -Sabine
Here is the relevant code:
setMarkers(map, beaches);
}
var beaches = [
['Devotion', 40.710431,-73.948432, 0],
['Tester', 40.711223,-73.958416, 1],
];
function setMarkers(map, locations) {
var image = new google.maps.MarkerImage('biker.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(32, 32),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32)
);
var newimage = new google.maps.MarkerImage('biker_click.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(32, 32),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32)
);
var shape = {
coord: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
shape: shape,
title: beach[0],
zIndex: beach[3],
});
}
function markerClick() {
console.log('click');
}
google.maps.event.addListener(marker, 'click', markerClick);
function markerClick() {
var playing = sm2.toggle('http://mm1.ellieirons.com/wp-content/uploads/2012/03/beeps_bubbles.mp3', true);
if (playing) {
this.setIcon(newimage);
} else {
this.setIcon(image);
}
}
Suppose you have an array of URLs:
var sounds = ["http://mm1.ellieirons.com/wp-content/uploads/2012/03/beeps_bubbles.mp3",
"http://mm1.ellieirons.com/wp-content/uploads/2012/03/beeps_bubbles2.mp3"];
Then you could try something like this:
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
shape: shape,
title: beach[0],
zIndex: beach[3]
});
marker.sound = sounds[i]; //Storing associated sound in marker
google.maps.event.addListener(marker, 'click', markerClick);
}
And modify the handler to this:
function markerClick() {
var playing = sm2.toggle(this.sound, true);
if (playing) {
this.setIcon(newimage);
} else {
this.setIcon(image);
}
}
这篇关于添加声音标记的数组 - 谷歌地图的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!