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.
I have 2 normal javascripts function and one jquery function for my application using google maps. In brief, it looks like this
<script type="text/javascript">
window.onload = function()
{
initialize();
}
</script>
<script type="text/javascript">
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 < 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+"&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);
}
});
}
google.maps.event.addDomListener(window, ‘load’, initialize);
The reason why I’m doing this is because I can’t seem to get latlng. What i did at first was to initialize the maps with window.onload = function(){ initialize() } and call the .ajax function in a $(window).load(function(){...}); I can’t get it right either ways.
Sorry if this sounds confusing. I’ll add in more details if this isn’t enough.
Edit:
results[0].geometry.location 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.
More Edit:
Added full length of code
ASSUMING that results[0].geometry.location is ALREADY a valid location. I do not see this to be a fact, but you might have that already
You might want to check if the seperation with comma is correct