Witam wszystkich
w kodzie JS, w pętli ustawionej przez PHP, odczytuje współrzędne długości i szerokości geograficznej, wg. podanego adresu z tablicy PHP:
<script type="text/javascript">
$(function(){
$("#btnid").click(function() {
var geocoder = new google.maps.Geocoder();
var counter = 0;
var key;
var addr;
var latitude;
var longitude;
var myArray= new Array();
<?php foreach ($phpArray as $key => $value) : ?>
key = <?php echo $value["id"] ?>;
addr = '<?php echo $value["address"] ?>';
latitude = 0;
longitude = 0;
geocoder.geocode({'address': addr}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
console.log(latitude+' '+longitude);
setMyPositions();
} else {
//alert("Geocoder failed due to: " + status);
}
});
var setMyPositions= function(){
myArray[counter] = {
"id" : key,
"lng" : longitude,
"lat" : latitude,
};
}
counter++;
<?php endforeach; ?>
if (myArray.length > 0) {
$.ajax({
type: "POST",
url: 'adres url',
data: {'arr': myArray},
dataType: "text",
complete: function (data) {
},
error: function (data) {
}
});
}
});
});
//-->
</script>
Jednak nie działa poprawnie... nie widzie parametrów longitude oraz latitude