Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please refer the following example which i have used already.,</p> <p><strong>Step #1 :</strong> Include the Three script Files in header of your page.,like</p> <pre><code>(i). &lt;script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=Your_API_KEY"&gt;&lt;/script&gt; (ii).&lt;script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; (iii).&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"&gt;&lt;/script&gt; </code></pre> <p><strong>Step #2 :</strong> Scripts On Page</p> <pre><code>&lt;script type="text/javascript"&gt; //initialize the map window jQuery(document).ready(function () { load(); }); jQuery(window).unload(function () { GUnload(); }); var map; var geocoder; var directionDisplay; var directionsService = new google.maps.DirectionsService(); function load() { if (GBrowserIsCompatible()) { geocoder = new GClientGeocoder(); map = new GMap2(document.getElementById('map')); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); //map.setCenter(new GLatLng(35.048629,-0.820663), 4); searchLocations(); document.getElementById('directions-panel').innerHTML = ''; var url_new = ''+ benObj.TEMPLATE_DIR +'/print.html'; var print_icon_url_new = '&lt;a href="javascript:void(0);" class="print" onClick="window.open(\'' + url_new + '\');"&gt;Print&lt;/a&gt;&lt;a href="#" class="link"&gt;Link&lt;/a&gt;'; jQuery('#print_icon').html(print_icon_url_new); } } //Search Locations with address input function searchLocations() { var address = document.getElementById('addressInput').value; // alert(address); var address_new = jQuery("#addressInput_new").val(); if (address_new != "Enter City or Zip") { jQuery("#loc1").html(address_new); } geocoder.getLatLng(address, function (latlng) { //alert(latlng); if (!latlng) { alert(address + ' not found'); } else { searchLocationsNear(latlng); } }); } // Search Near By Location to place the Markers and Information windows function searchLocationsNear(center) { var radius = document.getElementById('radiusSelect').value; var searchUrl = ''+ benObj.BASE_ROOT +'/mapmarker?lat=' + center.lat() + '&amp;lng=' + center.lng() + '&amp;radius=' + radius + '&amp;format=raw'; jQuery.get(searchUrl, function (data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName('marker'); map.clearOverlays(); var sidebar = document.getElementById('sidebar'); var sidebar_val = ''; //sidebar.innerHTML = 'Results Found'; jQuery("#sidebar").html(sidebar_val); &lt;!--jQuery("#loc_count").html(markers.length);--&gt; if (markers.length == 0) { sidebar.innerHTML = 'No results found.'; map.setCenter(new GLatLng(35.048629, -0.820663), 4); return; } var bounds = new GLatLngBounds(); for (var i = 0; i &lt; markers.length; i++) { var name = markers[i].getAttribute('name'); var address = markers[i].getAttribute('address'); var phone_new = markers[i].getAttribute('phonenumber'); var distance = parseFloat(markers[i].getAttribute('distance')); var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')), parseFloat(markers[i].getAttribute('lng'))); var markerchar = "b"; var marker = createMarker(point, name, address, phone_new); map.addOverlay(marker); // var location_count = jQuery('#loc_count').val(); jQuery('#loc_count').val(i + 1); var sidebarEntry = createSidebarEntry(marker, name, address, distance, phone_new); jQuery('#sidebar').append(sidebarEntry); //sidebar.appendChild(sidebarEntry); // ScrollPane.getContentPane().appendChild(sidebarEntry); bounds.extend(point); } map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); jQuery('#sidebar').jScrollPane(); //jQuery('#sidebar').reinitialise(); }); } //To Create a Marker With Information Window function createMarker(point, name, address, phone_new) { var pinkIcon = new GIcon(G_DEFAULT_ICON); pinkIcon.image = ""+ benObj.IMAGE_DIR +"addr-pin-1.png"; var markerOptions = { icon: pinkIcon }; var marker = new GMarker(point, markerOptions); var event_calendar = "event_calendar"; var event_title = ""+ benObj.event_title +""; var display = "block"; var e_dt_start = jQuery("#dtstart").val(); var e_dt_end = jQuery("#dtend").val(); var e_start_timestamp = (formatTimestring(e_dt_start)); var e_end_timestamp = (formatTimestring(e_dt_end)); var e_desc = jQuery("#edesc").val(); var StrippedString = e_desc.replace(/(&lt;([^&gt;]+)&gt;)/ig, ""); var trimmed = StrippedString.replace(/^\s+|\s+$/g, ''); var html = '&lt;b&gt;' + name + '&lt;/b&gt; &lt;br/&gt;' + address + '&lt;br&gt;contact: ' + phone_new + '&lt;br&gt;&lt;br&gt;&lt;a href="javascript:void(0);" style="text-decoration:none;" onclick="addtocalender();" class="addtocal" id="add_to_cal"&gt;Add to Calendar&lt;div class="summary" style="display:none;"&gt;' + event_title + ' - "' + name + '"&lt;/div&gt;&lt;span class="dtstart date" title="' + e_dt_start + '" style="display:none;"&gt;8th Aug 2010&lt;/span&gt;&lt;span class="dtend date" title="' + e_dt_end + '" style="display:none;"&gt;01:30am - 12:00pm&lt;/span&gt;&lt;div class="event-desc" style="display:none;"&gt;' + trimmed + '&lt;/div&gt;&lt;div class="event-locate" style="display:none;"&gt;' + name + ',' + address + '&lt;/div&gt;&lt;/a&gt;&amp;nbsp;|&amp;nbsp;&lt;a href="javascript:void(0);" style="text-decoration:none;"&gt;Remind Me&lt;/a&gt;&lt;br&gt;&lt;br&gt;Get Direction From:&lt;br&gt;&lt;input type="hidden" id="start" value="' + address + '"&gt;&lt;input type="text" id="end" value="" style="border: 1px solid #ECE6D5;"&gt;&amp;nbsp;&lt;input type="button" value="GO" onclick="calcRoute();" style="border: 1px solid #ECE6D5;padding-left:5px;"&gt;'; GEvent.addListener(marker, 'click', function () { marker.openInfoWindowHtml(html); //jQuery(this).addtocal(); }); return marker; } // To Make Sidebar Entry If need function createSidebarEntry(marker, name, address, distance, phone_new) { var div = document.createElement('div'); var html = '&lt;div class="locrow clearfix"&gt;&lt;div class="left" style="width:240px;"&gt;&lt;span class="count" id="loc_count"&gt;' + jQuery("#loc_count").val() + '&lt;/span&gt;&lt;address&gt;&lt;strong&gt;' + name + '&lt;/strong&gt;' + address + '&lt;/address&gt;&lt;span class="mapdate"&gt;&lt;span class="icon date"&gt;&lt;/span&gt;'+ benObj.event_start_month_date +' &amp;ndash; '+ benObj.event_end_month_date_year +'&lt;/span&gt;&lt;/div&gt;&lt;div class="right" style="width:154px;"&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="icon phone"&gt;&lt;/span&gt;' + phone_new + '&lt;/li&gt;&lt;li&gt;&lt;span class="icon time"&gt;&lt;/span&gt;11 am &amp;ndash; 7 pm&lt;/li&gt;&lt;li&gt;&lt;span class="icon car"&gt;&lt;/span&gt;distance ' + distance.toFixed(1) + ' mi&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;'; div.innerHTML = html; div.style.cursor = 'pointer'; div.style.marginBottom = '5px'; GEvent.addDomListener(div, 'click', function () { GEvent.trigger(marker, 'click'); }); GEvent.addDomListener(div, 'mouseover', function () { div.style.backgroundColor = '#eee'; }); GEvent.addDomListener(div, 'mouseout', function () { div.style.backgroundColor = '#fff'; }); return div; } // To make a Directions If need function calcRoute() { directionsDisplay = new google.maps.DirectionsRenderer(); var start = document.getElementById('start').value; var end = document.getElementById('end').value; var url = "http://maps.google.co.in/maps?f=d&amp;source=s_d&amp;saddr=" + start + "&amp;daddr=" + end + "&amp;aq=0&amp;vpsrc=0&amp;hl=en&amp;doflg=ptm&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=5&amp;layer=c&amp;pw=2"; var print_icon_url = '&lt;a href="javascript:void(0);" class="print" onClick="window.open(\'' + url + '\');"&gt;Print&lt;/a&gt;&lt;a href="#" class="link"&gt;Link&lt;/a&gt;'; var request = { origin: start, destination: end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function (response, status) { if (status == google.maps.DirectionsStatus.OK) { var myOptions = { zoom: 7, mapTypeId: google.maps.MapTypeId.ROADMAP, center: new google.maps.LatLng(41.850033, -87.6500523) }; map = new google.maps.Map(document.getElementById('map'), myOptions); directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById('directions-panel')); directionsDisplay.setDirections(response); jQuery('#print_icon').html(print_icon_url); } }); } &lt;/script&gt; </code></pre> <p><strong>Step #3:</strong> To Create a XML For Markers and Information Windows</p> <pre><code>&lt;?php function mapMarker($center_lat,$center_lng,$radius) { $mysqli = $this-&gt;_getMySqlConnection(); // Start XML file, create parent node $dom = new DOMDocument("1.0"); $node = $dom-&gt;createElement("markers"); $parnode = $dom-&gt;appendChild($node); // Search the rows in the markers table $query = sprintf("SELECT phone,street_address_1, store_name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM locations HAVING distance &lt; '%s' ORDER BY distance LIMIT 0 , 10", $mysqli-&gt;real_escape_string($center_lat), $mysqli-&gt;real_escape_string($center_lng), $mysqli-&gt;real_escape_string($center_lat), $mysqli-&gt;real_escape_string($radius)); $result = $mysqli-&gt;query($query); header("Content-type: text/xml"); header('Access-Control-Allow-Origin: *'); $avoid_duplicate=""; // Iterate through the rows, adding XML nodes for each while ($row = @$result-&gt;fetch_assoc()) { if($avoid_duplicate!=$row['store_name']) { $node = $dom-&gt;createElement("marker"); $newnode = $parnode-&gt;appendChild($node); $newnode-&gt;setAttribute("name", $row['store_name']); $newnode-&gt;setAttribute("address", $row['street_address_1']); $newnode-&gt;setAttribute("lat", $row['lat']); $newnode-&gt;setAttribute("lng", $row['lng']); $newnode-&gt;setAttribute("distance", $row['distance']); $newnode-&gt;setAttribute("phonenumber", $row['phone']); $avoid_duplicate=$row['store_name']; } } $outXML=$dom-&gt;saveXML(); $result-&gt;close(); $mysqli-&gt;close(); return $outXML; } ?&gt; </code></pre> <p><strong>Step #4:</strong> HTML Part</p> <pre><code>&lt;div class="mapleft"&gt; &lt;div class="ScrollPane scroll-pane" id="sidebar" style="overflow: auto; height: 430px;"&gt;&lt;/div&gt; &lt;div class="mapshadow"&gt;&lt;/div&gt; &lt;/div&gt; &lt;input type="hidden" id="addressInput" value="&lt;?php echo $zip_code;?&gt;" /&gt; &lt;input type="hidden" id="radiusSelect" value="50" /&gt; &lt;input type="hidden" id="addressInput_temp" value="&lt;?php echo $zip_code;?&gt;" /&gt; &lt;input type="hidden" id="radiusSelect_temp" value="50" /&gt; &lt;input type="hidden" name="X_REQUESTED_WITH" value="XMLHttpRequest" /&gt; &lt;div class="mapright"&gt; &lt;div id="map" style="width: 475px; height: 450px"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="map-dir" id="directions-panel" style="float:right;width:488px;"&gt;&lt;/div&gt; &lt;input type="hidden" id="loc_count" value="1" /&gt; </code></pre> <p>These are the things which will produce the great out comes. I think this may help you to resolve your problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload