Reputation:
I am trying to figure out why the code below is not working. It works fine when the numbers are directly inserted into the variable (in the code below it's commented out). The alert from the variable extracted from JSON is also showing up fine, but when the variable extracted from JSON is inserted into map.setCenter or google.maps.Marker it does not work.
$(document).on('click', '#submit_button', function(){
var property_id = $('#property_id').val();
$.post('sql_search_by_id.php', {id : property_id}, function(data){
var json = $.parseJSON(data);
var lt = json.results[0].latitude;
var lg = json.results[0].longitude;
alert(lt + " - " + lg);
//var lt = 49; var lg = 15;
map.setCenter({lat: lt, lng: lg});
new google.maps.Marker({position: {lat: lt, lng: lg}, map: map});
});
});
Upvotes: -1
Views: 70
Reputation: 11808
Try using parseInt or parseFloat whichever you require.
$(document).on('click', '#submit_button', function(){
var property_id = $('#property_id').val();
$.post('sql_search_by_id.php', {id : property_id}, function(data){
var json = $.parseJSON(data);
var lt = parseInt(json.results[0].latitude);
var lg = parseInt(json.results[0].longitude);
alert(lt + " - " + lg);
//var lt = 49; var lg = 15;
map.setCenter({lat: lt, lng: lg});
new google.maps.Marker({position: {lat: lt, lng: lg}, map: map});
});
});
Upvotes: 1