0
td well?
I have a script in PHP that converts the ZIP code to Coordinate and I would like it to convert automatically according to the value of an input.
<input type="text" value="" id="cep" >
<input type="text" value="" id="latitude">
<input type="text" value="" id="longitude">
<?php
$cep = '01311-100';
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$cep.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
echo $lat;
echo $long;
?>
In the above he transforms the $cep zip into coordinate, but wanted when inserting the cep into the input he already converted and put the latitude and longitude in the corresponding inputs.
These values will be inserted in a mysql table.
Thank you!
In that case you’ll have to make one ajax to obtain the data according to the new zip code
– JuniorNunes
Sorry, I am beginner ajax would send the input value to php variable?
– Leandro Teraoka
No, ajax will make a request for:
http://maps.google.com/maps/api/geocode/json?address=CEP
, where ZIP code is the zip code entered in the input, the ajax response will come with the information you need.– JuniorNunes
Or if you do not allow, for a php script, to make this request and return the answer
– JuniorNunes