javascript - How to add image on google map -
i newbie.i want make web app based on google-map.i have written code displaying google map.here html code.
<html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <style> html, body, #map-canvas { height: 100%; margin: 0px; padding: 0px } .controls { margin-top: 16px; border: 1px solid transparent; border-radius: 2px 0 0 2px; box-sizing: border-box; -moz-box-sizing: border-box; height: 32px; outline: none; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); } #pac-input { background-color: #fff; font-family: roboto; font-size: 15px; font-weight: 300; margin-left: 12px; padding: 0 11px 0 13px; text-overflow: ellipsis; width: 400px; } #pac-input:focus { border-color: #4d90fe; } .pac-container { font-family: roboto; } #type-selector { color: #fff; background-color: #4d90fe; padding: 5px 11px 0px 11px; } #type-selector label { font-family: roboto; font-size: 13px; font-weight: 300; } </style> <title>places search box</title> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script> <script> function initialize() { var markers = []; var map = new google.maps.map(document.getelementbyid('map-canvas'), { maptypeid: google.maps.maptypeid.roadmap }); var defaultbounds = new google.maps.latlngbounds( new google.maps.latlng(-33.8902, 151.1759), new google.maps.latlng(-33.8474, 151.2631)); map.fitbounds(defaultbounds); var input = ( document.getelementbyid('pac-input')); map.controls[google.maps.controlposition.top_left].push(input); var searchbox = new google.maps.places.searchbox( (input)); google.maps.event.addlistener(searchbox, 'places_changed', function() { var places = searchbox.getplaces(); if (places.length == 0) { return; } (var = 0, marker; marker = markers[i]; i++) { marker.setmap(null); } markers = []; var bounds = new google.maps.latlngbounds(); (var = 0, place; place = places[i]; i++) { var image = { url: place.icon, size: new google.maps.size(71, 71), origin: new google.maps.point(0, 0), anchor: new google.maps.point(17, 34), scaledsize: new google.maps.size(25, 25) }; var marker = new google.maps.marker({ map: map, icon: image, title: place.name, position: place.geometry.location }); markers.push(marker); bounds.extend(place.geometry.location); } map.fitbounds(bounds); }); google.maps.event.addlistener(map, 'bounds_changed', function() { var bounds = map.getbounds(); searchbox.setbounds(bounds); }); } google.maps.event.adddomlistener(window, 'load', initialize); </script> <style> #target { width: 345px; } </style> </head> <body> <input id="pac-input" class="controls" type="text" placeholder="search location here"> <div id="map-canvas"></div> </body> </html>
now want put image icon on streets.please give useful suggestion, how can done?
in scenario, can add image markers map.
to draw marker image:
var marker = new google.maps.marker({ position: new google.maps.latlng(lat,lng), map: map, icon: '/path/to/image.png', zindex: 1 });
all need specifying coordinate of each image drawn onto map can randomly generate them. keep in mind have create marker object each of stars want draw. not reuse marker object.
Comments
Post a Comment