Google Map icon (pin) - how to define color?

后端 未结 2 1441
说谎
说谎 2021-01-12 19:25

is it possible to change color of pin placed on google map creatted by it\'s api? or have to use custom icon to do that?

it\'s google map api v3.

tnx in adv!

相关标签:
2条回答
  • 2021-01-12 19:54

    You can declare the image when you initialize the map:

    var overlay;
    
    function initialize() {
      var myLatLng = new google.maps.LatLng(0, 0);
      var myOptions = {
        zoom: 11,
        center: myLatLng,
        mapTypeId: google.maps.MapTypeId.SATELLITE
      };
    
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
      var swBound = new google.maps.LatLng(0, 0);
      var neBound = new google.maps.LatLng(0, 0);
      var bounds = new google.maps.LatLngBounds(swBound, neBound);
    
      // This is where you declare your image...
      var srcImage = 'images/yourimage.png';
      overlay = new USGSOverlay(bounds, srcImage, map);
    }
    

    More info here if you need it:

    http://code.google.com/apis/maps/documentation/javascript/overlays.html#CustomOverlays

    0 讨论(0)
  • 2021-01-12 19:58

    I know this question is old, but if anyone just wants to change to pin or marker color, then check out the documentation: https://developers.google.com/maps/documentation/android-sdk/marker

    when you add your marker simply set the icon-property:

    GoogleMap gMap;
    LatLng latLng;
    ....
    // write your code...
    ....
    gMap.addMarker(new MarkerOptions()
        .position(latLng)
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
    

    There are 10 default colors to choose from.

    0 讨论(0)
提交回复
热议问题