18

我已经阅读https://developers.google.com/maps/documentation/javascript/overlays有一段时间了,我似乎无法为我的地图工作获得自定义图标。

这是我的javascript:

var simplerweb = new google.maps.LatLng(55.977046,-3.197118);
var marker;
var map;

function initialize() {
    var myOpts = {
        center:    simplerweb,  
        zoom:      15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOpts);
    marker = new google.maps.Marker({
        map:        map,
        draggable:  true,
        animation:  google.maps.Animation.DROP,
        position:   simplerweb
    });
    google.maps.event.addListener(marker, 'click', toggleBounce);
}

function toggleBounce() {
  if (marker.getAnimation() != null) {
    marker.setAnimation(null);
  } else {
    marker.setAnimation(google.maps.Animation.BOUNCE);
  }
}

对于 gmaps 的完整初学者有什么建议吗?

4

4 回答 4

38
marker = new google.maps.Marker({
    map:map,
    // draggable:true,
    // animation: google.maps.Animation.DROP,
    position: new google.maps.LatLng(59.32522, 18.07002),
    icon: 'http://cdn.com/my-custom-icon.png' // null = default icon
  });
于 2012-04-29T22:40:51.083 回答
6

尝试

    var marker = new google.maps.Marker({
      position: map.getCenter(),
      icon: 'http://imageshack.us/a/img826/9489/x1my.png',
      map: map
    });

从这里

https://developers.google.com/maps/documentation/javascript/examples/marker-symbol-custom

于 2013-12-18T05:13:25.630 回答
5

您想要的颜色上的符号!

我几天来一直在寻找这个答案,这是创建自定义标记的正确且简单的方法:

' http://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=xxx%7c5680FC%7c000000&.png ' 其中 xxx 是文本,5680fc 是背景的十六进制颜色代码,000000 是文本的十六进制颜色代码.

这些标记是完全动态的,您可以创建任何您想要的气球图标。只需更改网址。

于 2017-12-29T12:05:31.847 回答
-5
LatLng hello = new LatLng(X, Y);          // whereX & Y are coordinates

Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),
                R.drawable.university);   // where university is the icon name that is used as a marker.

mMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(icon)).position(hello).title("Hello World!"));

mMap.moveCamera(CameraUpdateFactory.newLatLng(hello));
于 2016-01-14T12:40:38.247 回答