Is there away to embed google maps with inputted s

2020-05-03 09:44发布

I'm trying to make so when a user selects a country in a form and clicks submit, it redirects them to a page that has an embedded google maps widget that also is showing the country they selected previously.

I have tried my best to solve this, I have looked for solutions online and tried to do it myself by customizing the embed url and putting the country input into it

<?php
  include 'includes/connect.php';

  if(isset($_POST['submit'])) {

    $name = $_POST['f_name']." ".$_POST['l_name'];
    $sl1 = $_POST['sl1'];
    $sl2 = $_POST['sl2'];
    $country = $_POST['country'];
    $country = $_POST['county'];
    $team = $_POST['team'];
    $size = $_POST['size'];
    $quantity = $_POST['quantity'];

    if(isset($_POST['town'])) {
      $town = $_POST['town'];
    } else {
      $town = "N/A";
    }


    function get_cost($size, $quantity) {

      if($size == "S" || $size = "XS") {
        $jerseyCost = 45;
      } else {
        $jerseyCost = 50;
      }

      $Cost = $jerseyCost * $quantity;
      return $Cost;
    }

    $cost = get_cost($size, $quantity);

    function check_discount_percent($Cost) {
      if($Cost > 100) {
        return 10;
      }
      else if($Cost > 250) {
        return 25;
      } else {
        return "Not applicable to receive discount.";
      }
    }

    $discountPercent = check_discount_percent($cost);

    function get_total_cost($cost, $discountPercent) {
      if($discountPercent === 0){
        return $cost * ($discountPercent / 100);
      } else {
        return $cost;
      }
    }

    $totalCost = get_total_cost($cost, $discountPercent);

    if($country == "Ireland") {
      $deliveryTime = "3 days";
    } else if($country == "United States" ) {
      $deliveryTime = "3 weeks";
    } else if($country = "United Kingdom" || "France" || "Italy" || "Spain" || "Germany" || "Portugal" || "Switzerland" || "Denmark" || "Iceland") {
      $deliveryTime = "1 week";
    } else {
      $deliveryTime = "2 - 6 weeks";
    }

  }
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ajax Project | Cian Tiernan</title>
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/style.css">
  </head>
  <body>
    <header>
      <h3> Ajax Project </h3>
      <h4 id="home"><a href="index.php">Home</a></h4>
    </header>
    <div class="wrapper">
      <h2>Your order details!</h2>

      <h3> Name </h3>
      <p><?=$name?></p>

      <h3> Street Line 1 </h3>
      <p><?=$sl1?></p>

      <h3> Street Line 2 </h3>
      <p><?=$sl2?></p>

      <h3> Country </h3>
      <p><?=$country?></p>

      <h3> County </h3>
      <p><?=$county?></p>

      <h3> Town </h3>
      <p><?=$town?></p>

      <h3> Team </h3>
      <p><?=$team?></p>

      <h3> Size </h3>
      <p><?=$size?></p>

      <h3> Quantity </h3>
      <p><?=$quantity?></p>

      <h3> Items Cost </h3>
      <p><?=$cost?></p>

      <h3> Discount Percentage </h3>
      <p><?=$discountPercent?></p>

      <h3> Total Cost </h3>
      <p><?=$totalCost?></p>

      <div id="map">
        <iframe src="https://www.google.com/maps/place/<?=$country?>/embed" allowfullscreen></iframe>
        <h4>Delivery Time</h4>
        <p><?=$deliveryTime?></p>
      </div>

    </div>
  </body>
</html>

标签: php
2条回答
够拽才男人
2楼-- · 2020-05-03 10:12

you have to get a Google API key which is free then what your doing would work.

<?php
$country = "United States";
?>

<div id="map">
<iframe
  width="600"
  height="450"
  frameborder="0" style="border:0"
  src="https://www.google.com/maps/embed/v1/place?key={YOUR KEY HERE}&q=<?=$country?>" allowfullscreen>
</iframe>
</div>
查看更多
贪生不怕死
3楼-- · 2020-05-03 10:17

q is the parameter you use for address

<iframe 
        src="https://www.google.com/maps?z=4&f=q&output=embed&q=<?=$country?>">
</iframe>
查看更多
登录 后发表回答