如何创建与谷歌地图API v3的自定义图标标记?(How do you create a Marke

2019-06-24 02:05发布

我一直在读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一个完整的初学者?

Answer 1:

  • 演示: http://so.lucafilosofi.com/how-do-you-create-a-marker-with-a-custom-icon-for-google-maps-api-v3
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
  });
  • 注: https://developers.google.com/maps/documentation/javascript/overlays#Icons


Answer 2:

尝试

    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



Answer 3:

符号你想在颜色你想!

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

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

论文指标是完全动态的,你可以创造任何你想要的气球图标。 只需更改URL。



Answer 4:

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));


文章来源: How do you create a Marker with a custom icon for google maps API v3?