Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling $.ajax within javascript function
    primarykey
    data
    text
    <p><strong>This question is solved, even though the answer is irrelevant to the title. This was a badly structured question and to my disappointment I can't delete it as it is. Thanks for the help and looking at the code.</strong></p> <p>I have 2 normal javascripts function and one jquery function for my application using google maps. In brief, it looks like this</p> <pre><code>&lt;script type="text/javascript"&gt; window.onload = function() { initialize(); } &lt;/script&gt; &lt;script type="text/javascript"&gt; var geocoder; var markerE; var theLocation; var myLatlng; var infowindow = new google.maps.InfoWindow(); var markersArray = []; var eventMarkerArr = []; var retrievedLatLng; var retrievedLatLngArr = []; var map; $(document).ready(function(){ $('#tabs a').click(function(e){ e.preventDefault(); $(this).tab('show'); if($(this).attr("href").substring(1)=='event') { show('event'); hide('location'); } else if($(this).attr("href").substring(1)=='location') { show('location'); hide('event'); } }); }); function initialize() { geocoder = new google.maps.Geocoder(); var myLatlng = new google.maps.LatLng(1.3667, 103.7500); var myOptions = { zoom: 13, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP, styles:[{ featureType: "poi.attraction", stylers: [ { visibility: "off" } ]},{ featureType: "poi.business", stylers: [ { visibility: "off" } ] },{ featureType: "poi.government", stylers: [ { visibility: "off" } ] },{ featureType: "poi.medical", stylers: [ { visibility: "off" } ] },{ featureType: "poi.park", stylers: [ { visibility: "off" } ] },{ featureType: "poi.place_of_worship", stylers: [ { visibility: "off" } ] },{ featureType: "poi.school", stylers: [ { visibility: "off" } ] },{ featureType: "poi.sports_complex", stylers: [ { visibility: "off" } ] },{ } ] }; map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); if (postalArr) { for (var i = 0; i &lt; postalArr.length; i++ ) { codeAddress(postalArr[i]); } } else { document.getElementById("event_list").value = "There are no events!"; } var locationPin = 'images/green-pin.png'; } var address; var eventPin = "images/blue-pin.png"; function codeAddress(postal) { geocoder.geocode( {'address': postal + ", Singapore"}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); retrievedLatLng = results[0].geometry.location; var eventwindow = new google.maps.InfoWindow(); var markerE = new google.maps.Marker({ map: map, position: results[0].geometry.location, icon: eventPin, }); markerE.mycategory = "event"; markerE.setVisible(false); google.maps.event.addListener(markerE, 'click', function(){ eventwindow = new google.maps.InfoWindow({ content: "hello", }); eventwindow.open(map,marker); }); $.ajax({ type:"GET", url: "http://maps.googleapis.com/maps/api/geocode/json?latlng="+retrievedLatLng+"&amp;sensor=false", dataType: "jsonp", success: function(json){ if(json.status == 'OK') { alert("success"); } } }); eventMarkerArr.push(markerE); retrievedLatLngArr.push("codeAddress:"+retrievedLatLng); alert(retrievedLatLngArr[0]); } else { alert("Geocode was not successful for the following reason: " + status); } }); } </code></pre> <p>google.maps.event.addDomListener(window, 'load', initialize);</p> <p></p> <p>The reason why I'm doing this is because I can't seem to get <code>latlng</code>. What i did at first was to initialize the maps with <code>window.onload = function(){ initialize() }</code> and call the .ajax function in a <code>$(window).load(function(){...});</code> I can't get it right either ways.</p> <p>Sorry if this sounds confusing. I'll add in more details if this isn't enough.</p> <p><strong>Edit:</strong></p> <p><code>results[0].geometry.location</code> is the latitude longtitude that is produced from reverse geocoding a 6 digit postal code. I want the full address, but only have the 6 digit postal code. The latitude and longtitude is used to also place a marker on the google map. So to get the full address I'm trying to get a json result using the url provided by google.</p> <p><strong>More Edit:</strong> Added full length of code</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