javascript - find google map places with name from coordinates that is points in map -
i create google map coordinates comming database. in table have coordinates points google pointer in asp.net page. wants search name of city have coordinate of search name in db , highlight color in google map have following code fetch db coordinates:
<script type="text/javascript"> var markers = [ <asp:repeater id="rptmarkers" runat="server"> <itemtemplate> { <%--''<%# getimagefrombyte(databinder.eval(container.dataitem, "image")) %>' '--%> "title":"survey", <%-- "title": '<%# eval("name") %>',--%> "lat": '<%# eval("lat") %>', "lng": '<%# eval("long") %>', "description": "<div> <img src='' alt='alternate text1' /></div>", "image": "<div> <img src='<%#eval("photo")%>' width='150px' alt='picture not available survey' /></div>", "name":'<%# eval("name")%>', "phonenumber":'<%# eval("phonenumber")%>' } </itemtemplate> <separatortemplate> , </separatortemplate> </asp:repeater> ]; </script> <script type="text/javascript"> window.onload = function () { var mapoptions = { center: new google.maps.latlng(markers[0].lat, markers[0].lng), zoom: 8, maptypeid: google.maps.maptypeid.roadmap }; var infowindow = new google.maps.infowindow(); var map = new google.maps.map(document.getelementbyid("dvmap"), mapoptions); (i = 0; < markers.length; i++) { var data = markers[i] var mylatlng = new google.maps.latlng(data.lat, data.lng); var marker = new google.maps.marker({ position: mylatlng, map: map, title: data.title }); (function (marker, data) { google.maps.event.addlistener(marker, "click", function (e) { infowindow.setcontent(data.description+data.image+data.name+ '<br/>'+ data.phonenumber); infowindow.open(map, marker); }); })(marker, data); } } </script>
to deal issue, first have check if marker present on map or not. use following method know if city under search has latitude , longitude on map or not.
this method return true
if coordinates
of city under search present on map else return false
.
map.getbounds().contains(marker.getposition());
once returns true, can assign color.
hope helps!!
Comments
Post a Comment