I am trying to read some json format rest-api which is in my local host and then show their points on my google map, but there is a problem because I cannot get the latitude and longitude out of the getJSON block, I am new in JavaScript and rest-api. please help me and feel free to ask any question, BTW this is my code:
<script>
var b=true;
var lon=0.0;
var lat=0.0;
var center=null;
function myMap() {
$.getJSON('http://localhost:4567/game-net/name/megafun', function(data) {
console.log(data);
lat+=data[0].lattitude;
lon+=data[0].longtitude;
console.log(lat);
console.log(lon);
center= new google.maps.LatLng(lat,lon);
console.log(center);
});
console.log(lat);//this is 0 and if I dont initialize by zero will be undefined
console.log(center);
var myCenter = new google.maps.LatLng(35.741635,51.448145);
var mapCanvas = document.getElementById("map");
var mapOptions = {center: myCenter, zoom: 15};
var map = new google.maps.Map(mapCanvas, mapOptions);
....