$_default_address_zip = $_POST['_default_address_zip']; $_default_address_country = $_POST['_default_address_country']; // get latitude, longitude and formatted address $data_arr = geocode($_default_address_street . ',' . $_default_address_city . ',' . $_default_address_state . ',' . $_default_address_zip . ',' . $_default_address_country); // if able to geocode the address if ($data_arr) { $latitude = $data_arr[0]; $longitude = $data_arr[1]; $databaseConnection->addStoreInfo($_store_name, $_store_rating, $_store_category, $latitude, $longitude, $_default_address_street, '', $_default_address_city, $_default_address_state, $_default_address_zip, $_default_address_country); echo "<script>window.location.reload()</script>"; } else { echo "The address does not exist, please try again!"; } } else { $delete_store_name = $_POST['_delete_store']; $databaseConnection->deletStoreInfo($delete_store_name); } } ?> <?php // function to geocode address, it will return false if unable to geocode address function geocode($address) { // url encode the address $address = urlencode($address); // google map geocode api url $url = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDZwgb_z_wFGqrzvxbrLri_CXJRjklDoTM&address={$address}"; // get the json response $resp_json = file_get_contents($url); // decode the json