0

This is javascript function to access latitude longitude and city from json:

function parse()
{
var json = '<?php echo $json; ?>';
var events = jQuery.parseJSON(json);
var DateArray = new Array();
var size = Object.keys(events).length;
search(events);
}
 function search(events)
 {
  for ( i in events)
 {
if( typeof events[i] === 'object' )
{
 key= i.toLowerCase();
      if(key.indexOf("latitude") !== -1)
      {
      var lat = events[i];
      var longi = events['longitude'];
       // alert(lat + longi);
           initialize(lat,longi,'5');
          // DateArray = DateArray.concat(events[i]);
          // alert('DataArray');
       }
          search(events[i]);   
 }
 }
  }

I have this json:

{
   "type":"http://schema.org/Place",
   "class":"place",
   "city":"London",
   "geo":{
       "type":"http://schema.org/GeoCoordinates",
       "class":"geocoordinates",
       "latitude":"30",
       "longitude":"70"
    }
}

map code:

function initialize(a,b,zom){
    if (!a || !b ||!zom){
          var centerLoc=new google.maps.LatLng( 34.61701054652337,71.37824736488983);
          zoom=16;
    }
    else
    {
        alert(typeof a + typeof b + typeof zom);
        var zoom =parseInt(zom);
        var centerLoc=new google.maps.LatLng(a,b);
        alert('it works fine');
    }
       var mapProp = {
            center:centerLoc,
            zoom:zoom,
            //mapTypeId:google.maps.MapTypeId.ROADMAP
            mapTypeId:google.maps.MapTypeId.SATELLITE
       };
       var map=new google.maps.Map(document.getElementById("googleMap") ,mapProp);
       marker=new google.maps.Marker({
                  position:centerLoc,
                  title:'Click to zoom'
             });
        google.maps.event.addListener(marker,'click',function() {
                map.setZoom(map.getZoom()+1);
                map.setCenter(marker.getPosition());
       });
            marker.setMap(map);
}
       google.maps.event.addDomListenerOnce(window, 'load', initialize);

When lat long and city are initialized, initialized function is called with lat and long as parameters.

problem

When arguments are passed to initialize function to initialize google map, it shows that function is called as it alerts the values of parameters in called function.lat and long both are string of type as required. but this does not show google map.

Community
  • 1
  • 1
bkashaf
  • 152
  • 2
  • 12

0 Answers0