Javascript 如何在这个谷歌地图api中添加一个红气球标记?

Javascript 如何在这个谷歌地图api中添加一个红气球标记?,javascript,api,google-maps,Javascript,Api,Google Maps,我想在我的网站上添加谷歌地图(带街景)。我使用这个代码。当我单击地图上的点时,它可以将街景更改为该部分,并显示单击点信息。但是如何在单击点中添加红色气球标记?然后单击另一点,第一个红色气球标记将移动到新点。(只需单击以移动标记,而不是拖动标记)。谢谢 谷歌地图API示例 var映射; myPano变种; 客户机; nextPanoId变种; 函数初始化(){ var fenwayPark=new GLatLng(42.345573,-71.098326); var fenwayPOV={偏航:

我想在我的网站上添加谷歌地图(带街景)。我使用这个代码。当我单击地图上的点时,它可以将街景更改为该部分,并显示单击点信息。但是如何在单击点中添加红色气球标记?然后单击另一点,第一个红色气球标记将移动到新点。(只需单击以移动标记,而不是拖动标记)。谢谢


谷歌地图API示例
var映射;
myPano变种;
客户机;
nextPanoId变种;
函数初始化(){
var fenwayPark=new GLatLng(42.345573,-71.098326);
var fenwayPOV={偏航:370.64659986187695,俯仰:-20};
panoClient=新的GStreetviewClient();
map=newgmap2(document.getElementById(“map_canvas”);
赛特中心地图(芬威公园,15);
addListener(映射,“单击”,函数(覆盖,latlng){
panoClient.getNearestPanorama(latlng、showPanoData);
});
myPano=新的GStreetviewPanorama(document.getElementById(“pano”);
myPano.设置地点和POV(芬威公园,芬威POV);
addListener(myPano,“error”,handleNoFlash);
panoClient.getNearestPanorama(芬威公园,showPanoData);
}
函数showPanoData(panoData){
如果(panoData.code!=200){
GLog.write('showPanoData:服务器被拒绝,代码为:'+panoData.code);
回来
}
NEXTPAOID=panoData.links[0].panoId;
变量显示字符串=[
“全景ID:+panoData.location.panoId,
“LatLng:+panoData.location.LatLng,
“版权:”+panoData.Copyright,
“说明:”+panoData.location.Description,
下一个Pano ID:“+panoData.links[0].panoId”
].加入(“
”); openInfoWindowHtml(panoData.location.latlng,displayString); GLog.write('查看器移动到'+panoData.location.latlng'); myPano.setLocationAndPOV(panoData.location.latlng); } 函数next(){ //获取下一个panoId //请注意,这并不复杂。在块的末尾,它将被卡住 panoClient.getPanoramaById(nextPanoId,showPanoData); } 函数handleNoFlash(错误代码){ 如果(错误代码==603){ 警报(“错误:您的浏览器似乎不支持Flash”); 回来 } }
你应该看看这篇文章

<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps API Sample</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
    <script type="text/javascript">

    var map;
    var myPano;   
    var panoClient;
    var nextPanoId;

    function initialize() {
      var fenwayPark = new GLatLng(42.345573,-71.098326);
      var fenwayPOV = {yaw:370.64659986187695,pitch:-20};

      panoClient = new GStreetviewClient();      

      map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(fenwayPark, 15);
      GEvent.addListener(map, "click", function(overlay,latlng) {
        panoClient.getNearestPanorama(latlng, showPanoData);
      });

      myPano = new GStreetviewPanorama(document.getElementById("pano"));
      myPano.setLocationAndPOV(fenwayPark, fenwayPOV);
      GEvent.addListener(myPano, "error", handleNoFlash);  
      panoClient.getNearestPanorama(fenwayPark, showPanoData);
    }

    function showPanoData(panoData) {
      if (panoData.code != 200) {
        GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
        return;
      }
      nextPanoId = panoData.links[0].panoId;
      var displayString = [
        "Panorama ID: " + panoData.location.panoId,
        "LatLng: " + panoData.location.latlng,
        "Copyright: " + panoData.copyright,
        "Description: " + panoData.location.description,
        "Next Pano ID: " + panoData.links[0].panoId
      ].join("<br/>");
      map.openInfoWindowHtml(panoData.location.latlng, displayString);

      GLog.write('Viewer moved to' + panoData.location.latlng);
      myPano.setLocationAndPOV(panoData.location.latlng);
    }

    function next() {
      // Get the next panoId
      // Note that this is not sophisticated. At the end of the block, it will get stuck
      panoClient.getPanoramaById(nextPanoId, showPanoData);
    }

    function handleNoFlash(errorCode) {
      if (errorCode == 603) {
        alert("Error: Flash doesn't appear to be supported by your browser");
        return;
      }
    }  

    </script>
  </head>
  <body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;">
    <div id="map_canvas" style="width: 500px; height: 400px"></div>
    <div name="pano" id="pano" style="width: 500px; height: 300px"></div>
    <input type="button" onclick="next()" value="Next"/>
  </body>
</html>