如何使用谷歌地图构建此产品?

问题描述 投票:-2回答:1

我想构建一个具有不同地标的网站的精确复制品,以指向。

你能告诉我应该学什么才能做到吗?

到目前为止,我已经创建了这个并且不知道下一步该做什么:

https://jsfiddle.net/hasnain721/01v7s2m4/6/

我是一个非常基本的编码器btw!

提前致谢!

var map = new google.maps.Map(document.getElementById("map"), {
   center: new google.maps.LatLng(53.3478, -6.2597),
   zoom: 16,
   mapTypeId: google.maps.MapTypeId.ROADMAP
 });

 var infoWindow = new google.maps.InfoWindow({
   map: map
 });
 // Try HTML5 geolocation.
 if (navigator.geolocation) {
   navigator.geolocation.getCurrentPosition(function(position) {
       var pos = {
         lat: position.coords.latitude,
         lng: position.coords.longitude
       };
       //infoWindow.setPosition(pos);
       // infoWindow.setContent('<b>You are here.</b><br><b>Lat:</b> '+position.coords.latitude+'<br><b>Lon:</b> '+position.coords.longitude);  
       map.setCenter(pos);
       var marker = new google.maps.Marker({
         position: pos,
         map: map,
         title: String(pos.lat) + ", " + String(pos.lng),
       });

       //draws out the path from current location to landmark
       var flightPlanCoordinates = [{
           lat: position.coords.latitude,
           lng: position.coords.longitude
         },
         {
           lat: 21.4224779,
           lng: 39.8251832
         }
       ];
       var flightPath = new google.maps.Polyline({
         path: flightPlanCoordinates,
         geodesic: true,
         strokeColor: '#FF0000',
         strokeOpacity: 1.0,
         strokeWeight: 2
       });
       flightPath.setMap(map);

       //draws out the path from current location to landmark


     },

     function() {
       handleLocationError(true, infoWindow, map.getCenter());
     });


 } else {
   // Browser doesn't support Geolocation
   handleLocationError(false, infoWindow, map.getCenter());
 }
google-maps google-maps-api-3 google-maps-markers
1个回答
0
投票

您需要更改“flightPlanCoordinates”变量的坐标。

样本指向自由女神像:

  var flightPlanCoordinates = [
    {lat: position.coords.latitude, lng: position.coords.longitude},
    {lat: 40.689249, lng: -74.0445}
  ];
© www.soinside.com 2019 - 2024. All rights reserved.