I have json data, i want to display LatLng data on map. Now the given LatLng was displayed on map but I am not getting infoWindow when i click, please help. I have attaced my code below : here is my script tag. Please suggess me how to do this, once again thank you
<script>
var obj = {
"location": [
{
"street_address": {
"city": "Trichy",
"state": "TamilNadu",
"address_1": "Test address",
"country": "India"
},
"gps": {
"latitude": 32.67,
"longitude": -85.44
}
},
{
"street_address": {
"city": "Madurai",
"state": "TamilNadu",
"address_1": "Test address",
"country": "India"
},
"gps": {
"latitude": 28.65859029,
"longitude": 77.22063432
}
},
{
"street_address": {
"city": "Chennai",
"state": "TamilNadu",
"address_1": "Test address",
"country": "India"
},
"gps": {
"latitude": 67.1,
"longitude": -157.85
}
},
{
"street_address": {
"city": "Combiatore",
"state": "TamilNadu",
"address_1": "Test address",
"country": "India"
},
"gps": {
"latitude": 52.67,
"longitude": -95.44
}
},
{
"street_address": {
"city": "Tirunelveli",
"state": "TamilNadu",
"address_1": "Test address",
"country": "India"
},
"gps": {
"latitude": 25.9,
"longitude": -97.43
}
}
]
};
var place = [];
var locations = [];
for(var i = 0; i < obj["location"].length;i++){
//var data = {"latitude" : 0, "longitude" : 0};
//data["latitude"] = obj["location"][i]["gps"]
locations.push(obj["location"][i]["gps"]);
place.push(obj["location"][i]["street_address"]);
}
console.log(place);
console.log(locations);
var pointer = new google.maps.LatLng(51.508742,-0.120850);
function intialize(){
var mapOption = {
zoom : 3,
center : pointer,
mapTypeControl:true,
mapTypeControlOptions: {
style:google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),mapOption);
for(var i = 0; i < locations.length; i++){
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i]["latitude"], locations[i]["longitude"]),
icon: 'map-icon.png'
});
marker.setMap(map);
console.log(locations[i]["latitude"], locations[i]["longitude"]);
}
for(var i = 0;i < place.length; i++){
var infoWindow = new google.maps.InfoWindow({
content : new google.maps.InfoWindow(place[i]["address_1"], place[i]["city"],place[i]["country"],place[i]["state"])
});
google.maps.event.addListener(marker, 'click', function(){
infoWindow.open(map, marker);
});
console.log(place[i]["address_1"], place[i]["city"],place[i]["country"],place[i]["state"]);
}
}
google.maps.event.addDomListener(window, 'load', intialize);
</script>