Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, there is an error in the map initialization:</p> <pre><code>var mapOptions = { zoom: 7, center: new google.maps.LatLng( latitude+','+longitude ), mapTypeId: google.maps.MapTypeId.ROADMAP } </code></pre> <p>should be</p> <pre><code>var mapOptions = { zoom: 7, center: new google.maps.LatLng( latitude, longitude ), mapTypeId: google.maps.MapTypeId.ROADMAP } </code></pre> <p>And I recommend to setup shown event before geocoding call.</p> <p>So, this one should work</p> <pre><code>function openMap( recID ) { $( '#media_'+recID ).html( '&lt;div class="modal-header"&gt;'+ '&lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt;'+ '&lt;h3 id="myModalLabel"&gt;Embassy Location&lt;/h3&gt;'+ '&lt;/div&gt;&lt;div id=box_'+recID+'&gt;&lt;/div&gt;' ); $( '#media_'+recID ).css( { 'height':'400px', 'width':'600px' } ); $( '#box_'+recID ).css( { 'height':'100%', 'width':'100%' } ); // activate the modal before loading it with the map $('#media_'+recID).on('shown', function () { // capture the content and strip it of HTML, then encode it var embAddr = $.trim( $( '#'+recID+' .contactInfo .embAddr' ).text().replace( /[\s\xA0]{2,}/g, ' ' ) ); embAddr = htmlEscape(embAddr); console.log( embAddr ); var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': embAddr}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var latitude = results[0].geometry.location.lat() ; var longitude = results[0].geometry.location.lng(); console.log( 'lat: ',latitude,' long: ',longitude ); var mapOptions = { zoom: 7, center: new google.maps.LatLng( latitude,longitude ), mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById( "box_"+recID ), mapOptions); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }) } else { $( '#media_'+recID ).html( 'Could not find this location from the address given.&lt;p&gt;'+embAddr+'&lt;/p&gt;' ); $( '#media_'+recID ).modal( 'show' ); } }) }); $( '#media_'+recID ).modal( 'show' ); } </code></pre>
    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.
 

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