Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Would like to suggest an approach for this requirement:</p> <ol> <li><p>On search button click - be it (POST request or AJAX POST), send the request to server.</p></li> <li><p>Perform the search on server 'search()' action.</p></li> <li><p>There are two responsibilities of search() action - 1. Show search result. 2. Show corresponding Markers on Map</p></li> <li><p>Search result will be the data and representation, be it 'div'/'table/tr/td'. This representation is generated on server without using any client resources and client side processing time. So the 'SearchView' can return both data and representation.</p></li> <li><p>Another responsibility is showing the markers corresponding to each search result. This is totally client responsibility. So lets keep it separate from the first responsibility. Using the JSON serialization library inject the serialized 'markers' json array in the 'SearchView' instead of mixing it with search result. The only time you might want to have the markers details with tightly bind to each search result is when you want to highlight the markers on click of individual search results. The use case could be initially show all the search results and show all the markers. Then when user clicks/hovers over (considering this is not targeted for mobile as hover cannot work there) the individual search result you can reposition the marker or add label or more information to selected search result.</p></li> <li><p>Also you might want to have the script in a separate file to avoid loading it on each search action. And from SearchView you can just call the 'InitializeMap()' JS function passing it the JSON serialized Markers and the initial map position. </p></li> <li><p>Using the JSON would be better approach and it provides the future flexibility to convert the application to AJAX easily. Also it is faster than parsing the HTML using Jquery for getting the marker details.</p> <pre><code>function InitializeMap(initialMapPosition,markers){ var latlng = new google.maps.LatLng(initialMapPosition.latitude,initialMapPosition.longitude); var options = { zoom: 15, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP // this could be as per your requirement. }; var map = new google.maps.Map($('#map-canvas')[0], options); // Place markers on map for( i = 0; i &lt; markers.length; i++) { var latLng = new google.maps.LatLng(markers[i].lat, markers[i].lng); var marker = new google.maps.Marker({ position: latLng, map: map }); } </code></pre> <p>}</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    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.
    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