0

Googleマップアプリケーションを使用していますが、通常表示される一般的な赤いアイコンの代わりにカスタムアイコンを配置したいと思います。しかし、私が何をしても、別のアイコンを設定することはできません。常に赤いアイコンとして表示されます。アイコンのURLにhttpsを含めることができないと読んだので、画像ホストにアップロードしましたが、アイコンを変更できません。マップ上にカスタムアイコンを表示するにはどうすればよいですか、それともbingを使用する必要がありますか?

function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
      zoom: 10,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  }

  function codeAddress() {
  initialize();
    var address = document.getElementById("address").value;
    range = document.getElementById("distance").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map,
            icon: "http://labs.google.com/ridefinder/images/mm_20_red.png"
            position: results[0].geometry.location

        });

        lat1 = results[0].geometry.location.lat();
        lng1 = results[0].geometry.location.lng();

      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
    load();
  }

それが言うところに注意してください:

icon: "http://labs.google.com/ridefinder/images/mm_20_red.png"

何を変更しても、常に赤い一般的なアイコンが表示されます。

4

1 に答える 1

0

マーカー画像は、ページHTTPHTTPSページの両方に読み込むことができます。ただし、スキームが含まれているページのスキームと一致していることを確認する必要があります(または、少なくとも、ページが一致しているHTTPS場合は必ず使用してください)。

オブジェクトにタイプミスがあるようですMarkerOptions。アイコン文字列の後にコンマがありません。

    var marker = new google.maps.Marker({
        map: map,
        icon: "http://labs.google.com/ridefinder/images/mm_20_red.png",
        position: results[0].geometry.location

    });
于 2013-03-11T03:03:41.040 に答える