javascript - can i change default AB of marker in google map? -
following javascript code. cant find change default behaviour of b c. can refer example links. googled , tried cant find favourable output. checked question cant find result. change default icon of marker in route
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript"> var combinedresults; var directionsresultsreturned = 0; function gdirrequest(service, waypoints, userfunction, waypointindex, path) { // set defaults waypointindex = typeof waypointindex !== 'undefined' ? waypointindex : 0; path = typeof path !== 'undefined' ? path : []; // next set of waypoints var s = gdirgetnextset(waypoints, waypointindex); // build request object var startl = s[0].shift()["location"]; var endl = s[0].pop()["location"]; var request = { origin: startl, destination: endl, waypoints: s[0], travelmode: google.maps.travelmode.driving, unitsystem: google.maps.unitsystem.metric, optimizewaypoints: false, provideroutealternatives: false, avoidhighways: false, avoidtolls: false }; service.route(request, function(result, status) { if (status == google.maps.directionsstatus.ok) { console.log(status); if (directionsresultsreturned == 0) { // first bunch of results in. new combinedresults object combinedresults = result; directionsresultsreturned++; } else { // building legs, overview_path, , bounds in consolidated object. not complete // directionresults object, enough draw path on map, need combinedresults.routes[0].legs = combinedresults.routes[0].legs.concat(result.routes[0].legs); combinedresults.routes[0].overview_path = combinedresults.routes[0].overview_path.concat(result.routes[0].overview_path); combinedresults.routes[0].bounds = combinedresults.routes[0].bounds.extend(result.routes[0].bounds.getnortheast()); combinedresults.routes[0].bounds = combinedresults.routes[0].bounds.extend(result.routes[0].bounds.getsouthwest()); directionsresultsreturned++; } path = path.concat(result.routes[0].overview_path); if (s[1] != null) { gdirrequest(service, waypoints, userfunction, s[1], path) } else { //console.log(result); //response.routes[0].overview_path=path; directionsdisplay.setdirections(combinedresults); //userfunction(path); } } else { console.log(status); } }); } function gdirgetnextset (waypoints, startindex) { var max_waypoints_per_request = 8; var w = []; // array of waypoints return if (startindex > waypoints.length - 1) { return [w, null]; } // no more waypoints process var endindex = startindex + max_waypoints_per_request; // adjust waypoints, because google allows include start , destination latlongs free! endindex += 2; if (endindex > waypoints.length - 1) { endindex = waypoints.length ; } // latlongs (var = startindex; < endindex; i++) { w.push(waypoints[i]); } if (endindex != waypoints.length) { return [w, endindex -= 1]; } else { return [w, null]; } } var driver_complete_sites = <?php echo json_encode($driver_complete_sites); ?>; var driver_incomplete_sites = <?php echo json_encode($driver_incomplete_sites); ?>; var driverlat = '<?php echo $driver_last_lat; ?>'; var driverlng = '<?php echo $driver_last_lng; ?>'; complete_icon = '<?php echo $this -> config -> base_url();?>images/tick.png'; incomplete_icon ='<?php echo $this -> config -> base_url();?>images/marker.png'; driver_pos_icon ='<?php echo $this -> config -> base_url();?>images/car_marker.png'; var directionsservice = new google.maps.directionsservice(); directionsdisplay = new google.maps.directionsrenderer(); var centerlng = 0; var centerlat = 0; if (driver_incomplete_sites != null){ if (driver_incomplete_sites.length>0){ //centerlat = driver_incomplete_sites[0].latitude; //centerlng= driver_incomplete_sites[0].longitude; centerlng = -81.7170 centerlat = 27.8333 } } if (driver_complete_sites != null){ if (driver_complete_sites.length>0){ length = driver_complete_sites.length - 1; //centerlat = driver_complete_sites[0].latitude; //centerlng= driver_complete_sites[0].longitude; centerlng = -81.7170 centerlat = 27.8333 //driverlat = driver_complete_sites[length].latitude; //driverlng= driver_complete_sites[length].longitude; } } if (centerlng == 0 && centerlat == 0){ centerlng = -81.7170 centerlat = 27.8333 } var latlngbounds = new google.maps.latlngbounds(); var map = new google.maps.map(document.getelementbyid('map'), { zoom: 6, center: new google.maps.latlng(centerlat, centerlng), maptypeid: google.maps.maptypeid.roadmap }); directionsdisplay.setmap(map); var infowindow = new google.maps.infowindow(); var waypoints = []; var end = null; var marker, i; if (driver_complete_sites != null){ if (driver_complete_sites.length>0){ var skip=driver_complete_sites.length - 1; var travelwaypoints=[]; (var key in driver_complete_sites) { latlngbounds.extend(new google.maps.latlng(driver_complete_sites[key].latitude,driver_complete_sites[key].longitude)); var directionsservice = new google.maps.directionsservice(); if (key == skip){ travelwaypoints.push({location: new google.maps.latlng(driver_complete_sites[key].latitude, driver_complete_sites[key].longitude)}); end = new google.maps.latlng(driver_complete_sites[key].latitude, driver_complete_sites[key].longitude); break; } else{ travelwaypoints.push({location: new google.maps.latlng(driver_complete_sites[key].latitude, driver_complete_sites[key].longitude)}); } /*if (key == 0){ start = new google.maps.latlng(driver_complete_sites[key].latitude, driver_complete_sites[key].longitude); }else if (key == skip){ end = new google.maps.latlng(driver_complete_sites[key].latitude, driver_complete_sites[key].longitude); }else{ var address = new google.maps.latlng(driver_complete_sites[key].latitude, driver_complete_sites[key].longitude); if (address !== "") { waypoints.push({ location: address, //title: driver_complete_sites[key].latitude+","+driver_complete_sites[key].longitude, //icon: complete_icon, stopover: true }); } }*/ } if (end != null){ gdirrequest(directionsservice, travelwaypoints, function drawgdirline(path) { //directionsdisplay.setdirections(path); //var line = new google.maps.polyline({clickable:false,map:map,path:path}); }); }else{ marker = new google.maps.marker({ position: new google.maps.latlng(driver_complete_sites[0].latitude, driver_complete_sites[0].longitude), map: map, title: driver_complete_sites[0].latitude+","+driver_complete_sites[0].longitude, icon: complete_icon }); } latlngbounds.extend(new google.maps.latlng(driverlat,driverlng)); marker = new google.maps.marker({ position: new google.maps.latlng(driverlat, driverlng), map: map, title: driverlat+","+driverlng, icon: driver_pos_icon }); } } if (driver_incomplete_sites != null){ if (driver_incomplete_sites.length>0){ (var key in driver_incomplete_sites) { latlngbounds.extend(new google.maps.latlng(driver_incomplete_sites[key].latitude,driver_incomplete_sites[key].longitude)); //alert(driver_incomplete_sites[key].longitude) marker = new google.maps.marker({ position: new google.maps.latlng(driver_incomplete_sites[key].latitude, driver_incomplete_sites[key].longitude), map: map, title: driver_incomplete_sites[key].latitude +","+ driver_incomplete_sites[key].longitude, icon: incomplete_icon }); } } } if (driver_incomplete_sites.length>0 || driver_complete_sites.length > 0){ map.fitbounds(latlngbounds); } </script>
i don't think can change them, can tell api not draw them, , draw them different icons yourself.
when set directionsrenderer have set suppressmarkers
true
:
var directionsdisplay = new google.maps.directionsrenderer({ suppressmarkers: true });
you can draw new markers:
var startmarker = new google.maps.marker({icon: aicon, map: map, position: startl}); var stopmarker = new google.maps.marker({icon: bicon, map: map, position: endl});
Comments
Post a Comment