我在数组中有经纬度数。我想在Google Map中显示多个标记

时间:2018-08-04 20:39:27

标签: ios xcode google-maps google-maps-markers swift4

我在数组中有经纬度数。我想在Google Map中显示多个标记。我是编程新手。

****我的当前代码****

导入UIKit 导入GoogleMaps

let mapView = GMSMapView()

ViewController类:UIViewController {

let lattitudeary = ["28.5355","28.7041","29.9457","30.0869"]
let longitudeary = ["77.3910","77.1025","78.1642","78.2676"]

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.


    view = mapView

    var marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
    marker.title = "Sydney"
    marker.snippet = "Australia"
    marker.map = mapView



//    var coords = [[-33.86,151.20],[28.5355,77.1025],[29.9457,78.1642]]

    var coords = [[lattitudeary.count],[longitudeary.count]]

    for coord in coords {
        var marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(coord[0]), longitude: CLLocationDegrees(coord[1]))
        marker.map = mapView

    }

}

1 个答案:

答案 0 :(得分:2)

首先将Google Maps与您的应用程序集成 Google Maps iOS SDK

然后尝试将标记添加到地图 Adding a Map with a Marker

  firebase.initializeApp(config);
  var order = firebase.database().ref("order");
  
  order.on("value", function(snapshot) {
     console.log(snapshot.val());
  }, function (error) {
     console.log("Error: " + error.code);
  });
  
  var submitOrder = function () {
  
  var orderId = $("#orderOrderId").val();
  var shipping = $("#orderShipping").val();
  var subtotal = $("#orderSubtotal").val();
  var total = $("#orderTotal").val();
  };
  
  order.limitToLast(1).on('child_added', function(childSnapshot) {
      order = childSnapshot.val();
      $("#orderId").html(order.orderId)
      $("#shipping").html(order.shipping)
      $("#subtotal").html(order.subtotal)
      $("#total").html(order.total)
      $("#link").attr("https://wishywashy-179b9.firebaseio.com/", order.link)
      });

最后使用for循环将多个标记添加到地图。 Swift Control Flow

<html>
   <head>
     <script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"></script>
     <script src="https://cdn.firebase.com/libs/firebaseui/2.5.1/firebaseui.js"></script>
     <link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/2.5.1/firebaseui.css" />
    <!-- <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script> -->
    <!-- Load the jQuery library, which we'll use to manipulate HTML elements with Javascript. -->
    <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
    <!-- Load Bootstrap stylesheet, which will is CSS that makes everything prettier and also responsive (aka will work on all devices of all sizes). -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  </head>
      <!-- <script type = "text/javascript" src = "data.js"></script> -->
   <body>
     <script type = "text/javascript" src = "data.js"></script>
     <div class="container">
        <h1>Merchant Portal</h1>
        <h3>Order Lists</h3>
        <table class="table table-striped">
          <thead>
            <tr>
              <th>Order ID</th>
              <th>Shipping Price</th>
              <th>Subtotal</th>
              <th>Total</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <!-- This is empty for now, but it will be filled out by an event handler in application.js with the most recent recommendation data from Firebase. -->
              <td id="orderId"></td>
              <td id="shipping"></td>
              <td id="subtotal"></td>
              <td id="total"></td>
            </tr>
          </tbody>
        </table>    
       </body>
       </html>