如何在谷歌地图上显示位置列表

时间:2012-10-25 18:45:28

标签: iphone ios ipad

我正在创建一个iPhone应用程序,我需要从gps获取纬度经度。现在我调用update-location delegate方法并在数组中添加新位置之后我需要显示所有纬度经度(位置)护目镜地图和所有地点之间的路线。

请帮我显示路线。 提前致谢

1 个答案:

答案 0 :(得分:0)

以下是使用Google Maps javascript api的方法。

<style>
  #map_canvas {
    height: 190px;
    width: 300px;
    margin-top: 0.6em;
  }
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<div id="map_canvas" ></div>

<script language="javascript" type="text/javascript">  
var latitude = 44.056389;
var longitude = -121.308056;

function initialize() {
        var mapOptions = { 
          center: new google.maps.LatLng(latitude,longitude),
          zoom: 9,
          streetViewControl: false,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById('map_canvas'),
          mapOptions);

        // Create a draggable marker which will later on be binded to a
        // Circle overlay.
        var marker = new google.maps.Marker({
          map: map,
          position: new google.maps.LatLng(latitude,longitude),
          draggable: true
        });

        // Add a Circle overlay to the map.
        var circle = new google.maps.Circle({
            strokeColor: "#0000FF",
            strokeOpacity: 0.4,
            strokeWeight: 2,
            fillColor: "#0000FF",
            fillOpacity: 0.20,
            map: map,
            radius: 16000 // meters
        });

        circle.bindTo('center', marker, 'position');

        google.maps.event.addListener(marker, 'dragend', function() {
            var location = marker.getPosition();
            latitude = location.lat();
            longitude = location.lng();
        });

        google.maps.event.addListener(autocomplete, 'place_changed', function() {
          var place = autocomplete.getPlace();
          var location = place.geometry.location;
          map.setCenter(location);
          map.setZoom(9);  // Why 9? Because it looks good.
          marker.setPosition(location);
          latitude = location.lat();
          longitude = location.lng();
        });

      }
</script>