Javascript Google地图,按经度和纬度坐标显示图钉[重复]

     2023-02-23     77

关键词:

【中文标题】Javascript Google地图,按经度和纬度坐标显示图钉[重复]【英文标题】:Javascript Google map, show pins by longitude and latitude coordinates [duplicate] 【发布时间】:2014-01-07 19:46:18 【问题描述】:

您好,我有一个 Javascript 代码,它显示了一个带有引脚的地图,使用那里的位置作为地址。 地址是从数组中读取的,数组结构是这样的:

var locations = ["1915 Edgewater Drive,Orlando,FL", "5555 Kirkman Rd.,Orlando,FL", "4965 Oak Ridge Road,Orlando,FL", "3011 E Colonial Dr,Orlando,FL", "300 Park Avenue,Winter Park,FL"];

用图钉显示地图的代码如下:

function initialize() 
  //Planned direction display
  directionsDisplay = new google.maps.DirectionsRenderer(
      polylineOptions : 
          strokeColor : 'brown',
          strokeOpacity : 0.7,
          strokeWeight : 3
      ,
      suppressMarkers : true,
      suppressPolylines : true
  );

  //actual direction display
  directionsDisplayActual = new google.maps.DirectionsRenderer(
      polylineOptions : 
          strokeColor : 'brown',
          strokeOpacity : 0.7,
          strokeWeight : 3
      ,
      suppressMarkers : true,
      suppressPolylines : true
  );

    geocoder = new google.maps.Geocoder();
    geocoder.geocode(  'address': locations[0] , function(results, status) 
        if (status == google.maps.GeocoderStatus.OK) 

        var chicago = new google.maps.LatLng(results[0].geometry.location.ob, results[0].geometry.location.pb);
          var mapOptions = 
                zoom: 6,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: chicago
          
          map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
          map_actual = new google.maps.Map(document.getElementById('map-actual'), mapOptions);
          calcRoute();
        
    );


现在我没有使用带有地址的位置,而是使用了一系列类似的经度和纬度坐标:

var coordinates = [[28.378929,-80.6006008],[28.378628084853,-80.600730804958],[28.378956475407,-80.600553605881],[28.378929693408,-80.60055175679],[28.378785540514,-80.60065325285],[28.378935283517,-80.600646565422],[28.378950753943,-80.600504807166]]

那么如何更改我的代码以使用这些坐标而不是位置地址?

谢谢。

【问题讨论】:

【参考方案1】:

试试这个:

var coordinates = [[28.378929,-80.6006008],[28.378628084853,-80.600730804958],[28.378956475407,-80.600553605881],[28.378929693408,-80.60055175679],[28.378785540514,-80.60065325285],[28.378935283517,-80.600646565422],[28.378950753943,-80.600504807166]];
// loop through your array of coordinates
for(var i = 0; i < coordinates.length; i++)
    // create a new marker and add it to the map
    var marker = new google.maps.Marker(
        position: new google.maps.LatLng(coordinates[i][0], coordinates[i][1]),
        map: map
    );

编辑:您使用LatLng 对象而不是对地址进行地理编码

【讨论】:

对不起,我是谷歌地图的新手,我想更改实际代码,我不知道如何在我的代码中使用你的。 你能说明你在哪里使用你的var locations吗?

使用 Google 静态地图检索经度/纬度的问题

】使用Google静态地图检索经度/纬度的问题【英文标题】:Issueretrievinglongitude/latitudeusingGoogleStaticMaps【发布时间】:2014-11-1900:31:25【问题描述】:我遇到了一个问题,我需要从传递给检索Google静态地图的AsyncTask的地址中获取经度/... 查看详情

在 Javascript 中使用 DJango 模板标签添加 Google 地图标记

】在Javascript中使用DJango模板标签添加Google地图标记【英文标题】:AddingGoogleMapMarkerswithDJangoTemplateTagsinJavascript【发布时间】:2012-02-1001:59:22【问题描述】:我正在尝试使用Django模板标签变量作为纬度和经度向地图添加一堆地图标... 查看详情

php获取google地图的纬度和经度(代码片段)

查看详情

我可以向 Google 地图提供地址而不是纬度和经度吗?

】我可以向Google地图提供地址而不是纬度和经度吗?【英文标题】:CanIprovideaddressesinsteadoflatitudeandlongitudetoGoogleMaps?【发布时间】:2011-03-0522:03:56【问题描述】:我正在构建一个应用程序,用户可以在其中提供其列表的地址。要... 查看详情

如何使用 JSON 纬度数组和 JSON 经度数组在 Google 地图上显示折线?

】如何使用JSON纬度数组和JSON经度数组在Google地图上显示折线?【英文标题】:HowtoshowapolylineonGooglemapusingJSONarrayoflatitudeandJSONarrayoflongitude?【发布时间】:2018-08-1806:25:09【问题描述】:我正在制作一个需要在Google地图上显示一条... 查看详情

地理编码器谷歌地图经度和纬度查找

...查找,可以很好地使用这样的ajax调用:<scripttype="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false">&l 查看详情

为啥在 MKMapView 中放置在相同纬度和经度的图钉与 Google 地图中的图钉不同?

】为啥在MKMapView中放置在相同纬度和经度的图钉与Google地图中的图钉不同?【英文标题】:WhydoesapinplacedatthesamelatitudeandlongitudeinMKMapViewdifferfromoneinGoogleMaps?为什么在MKMapView中放置在相同纬度和经度的图钉与Google地图中的图钉不同... 查看详情

如何从谷歌地图自动完成中提取纬度和经度

...络应用程序:http://code.google.com/intl/en/apis/maps/documentation/javascript/examples/plac 查看详情

Google Maps API:使用 GPS 纬度经度协调器在地图上显示标记

】GoogleMapsAPI:使用GPS纬度经度协调器在地图上显示标记【英文标题】:GoogleMapsAPI:ShowmarkeronmapusingGPSlatitudelongitudecoordinators【发布时间】:2017-09-2215:09:37【问题描述】:我有不同的位置要显示在不同的地图上。以下是我拥有的一... 查看详情

如何在不使用 Google 地图的情况下将纬度/经度转换为 HTML5 坐标?

】如何在不使用Google地图的情况下将纬度/经度转换为HTML5坐标?【英文标题】:Howtoconvertlatitude/longitudetoHTML5coordinateswithoutusingGoogleMaps?【发布时间】:2016-07-2213:18:17【问题描述】:目标是在不使用Google地图的情况下使用坐标数组... 查看详情

如何获得位于地图上的指针的纬度和经度?

...布时间】:2012-04-0609:56:05【问题描述】:我目前正在使用GoogleAPI在Google地图上指出位置。这是google-maps-utility-library-v3有链接http://google-maps-utility-library-v3.googleco 查看详情

谷歌地图 - 来自数据库经度和纬度的多个标记未显示在地图上

...中获取详细信息并将它们放入php数组中,然后将其传递给javascript以生成Google地图:<?php$query=\'sel 查看详情

django 数据渲染到 JavaScript 以制作具有纬度和经度的地图折线

】django数据渲染到JavaScript以制作具有纬度和经度的地图折线【英文标题】:djangodatarendertoJavaScripttomakeamappolylinewithlatitudeandlongitude【发布时间】:2020-11-1307:17:03【问题描述】:我有一个名为MapLocation的模型,在MapLocation模型中我有... 查看详情

Google Maps API - 如何在不显示地图的情况下从自动完成获取纬度和经度?

】GoogleMapsAPI-如何在不显示地图的情况下从自动完成获取纬度和经度?【英文标题】:GoogleMapsAPI-howtogetlatitudeandlongitudefromAutocompletewithoutshowingthemap?【发布时间】:2012-11-0820:11:42【问题描述】:我正在尝试从AutocompleteGoogleMapsAPI获... 查看详情

Javascript - 以编程方式按纬度和经度返回附近的地方

】Javascript-以编程方式按纬度和经度返回附近的地方【英文标题】:Javascript-Programaticallyreturnnearplacesbylatidudeandlongitude【发布时间】:2012-12-1212:48:21【问题描述】:是否有可能得到附近的地方,提供纬度和经度?例如,如果我想要... 查看详情

是否可以将地图中可拖动标记的纬度和经度(使用 javascript)转换为 HTML 表单?

】是否可以将地图中可拖动标记的纬度和经度(使用javascript)转换为HTML表单?【英文标题】:Isitpossibletogetthelatitudeandlongitudeofadraggablemarkerinamap(usingjavascript)intoaforminHTML?【发布时间】:2015-01-2504:46:36【问题描述】:我正在尝试获... 查看详情

如何在我的网站上向 Google 地图小部件添加用户输入标记,并从中获取纬度和经度数据?

】如何在我的网站上向Google地图小部件添加用户输入标记,并从中获取纬度和经度数据?【英文标题】:HowdoIaddauser-inputmarkertoGoogleMapswidgetonmywebsite,andgetthelatitudeandlongitudedatafromit?【发布时间】:2020-04-1815:52:09【问题描述】:现在... 查看详情

通过使用 Javascript 将邮政编码传递给 maps.google.com 来获取纬度经度

】通过使用Javascript将邮政编码传递给maps.google.com来获取纬度经度【英文标题】:FetchLatitudeLongitudebypassingpostcodestomaps.google.comusingJavascript【发布时间】:2011-02-0623:43:32【问题描述】:我的大型数据库中有邮政编码,其中包含SL59JH... 查看详情