如何改变标记图像

时间:2017-01-28 17:02:45

标签: javascript image maps marker

嘿我有代码每隔1秒自动移动标记 但它使用样品标记 我只需要将标记更改为另一个图像网址并添加一些CSS 像CustomMarker.prototype函数,但我无法合并它们!

https://s30.postimg.org/my0tsomb5/Screenshot_from_2017_01_28_16_13_26.png

function getPos() {//initial function to read the position
     estado = "livre";
     navigator.geolocation.getCurrentPosition(
onSuccess, onError,         {enableHighAccuracy:true});
     setTimeout(keep_alive, 1000); //read every 1 seconds
}

function onSuccess(position) {//read map and mark it in the map
lat = position.coords.latitude;
lon = position.coords.longitude;
console.log("Found - LAT: ", lat, "LON: ", lon);


var mapoptions = {
    zoom: 16,
    center: new google.maps.LatLng(lat,lon),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
};


map = new google.maps.Map(document.getElementById("map"), mapoptions);

var image = {
    url: 'try.png',
     scaledSize : new google.maps.Size(50, 60)
   };
 marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat,lon),
    map: map,
    icon: image,
    });

  //save_position();
 }

 function onError(error) {
  console.log('code: '    + error.code, 'message: ' + error.message);
 }

function keep_alive() {//read position and mark it in the map
 navigator.geolocation.getCurrentPosition(onRefresh,
 onError,     {enableHighAccuracy:true});
 //save_position();
 setTimeout(keep_alive, 1000); //read every 1 seconds   
 }

//refresh only the marker
function onRefresh(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;

console.log("Found - LAT: ", lat, "LON: ", lon);

marker.setPosition(new google.maps.LatLng(lat, lon));//refresh marker
map.setCenter(new google.maps.LatLng(lat, lon));
 //resfresh center of    the map
}

0 个答案:

没有答案