简体   繁体   English

如何从经纬度中获取价值以在脚本中创建Google Maps标记?

[英]How to get value from latitude and longitude to create google maps marker in script?

I have an input text in HTML and need to pass coordinates to make a marker in Google maps. 我有一个HTML输入文本,需要传递坐标才能在Google地图中做一个marker

jsfiddle.net/#&togetherjs=r3M9Kp7ff7 jsfiddle.net/#&togetherjs=r3M9Kp7ff7

How to pass it from HTML to a JavaScript with good type of data? 如何将其从HTML传递到具有良好数据类型的JavaScript?

<label for="latitude">Latitude</label>
<input id="latitude" type="text" ng-model="ctrl.department.latitude" class="form-control" required="" placeholder="Latitude" value=""/>
<label for="longitude">Longitude</label>
<input id="longitude" type="text" ng-model="ctrl.department.longitude" class="form-control" required="" placeholder="Longitude" value=""/>
<label for="map">Pozycja na mapie</label>
<div id="map">
<script>
function initMap() {
  var myLat = document.getElementById('latitude').value;
  var myLng = document.getElementById('longitude').value;
  var map = new google.maps.Map(document.getElementById('map'), {
                center: {lat: 51.75, lng: 19.46},
                zoom: 10,
                mapTypeId: 'roadmap'
});

var marker = new google.maps.Marker({
                 position:{myLat, myLng}, // not working
                 map:map,
});
</script>

In your script Try This One 在脚本中尝试这个

 <script>
      function initMap() {
        var myLat = document.getElementById('latitude').value;
        var myLng = document.getElementById('longitude').value;

        var myCenter = {lat: myLat, lng: myLng};

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 10,
          center: myCenter
        });

        var marker = new google.maps.Marker({
          position: myCenter,
          map: map
        });

      }
    </script>

Marker position syntax should be 标记位置的语法应为
position: {lat: myLat, lng: myLng} instead of this position:{myLat, myLng}, 位置:{lat:myLat,lng:myLng},而不是此位置:{myLat,myLng},

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Google地图中的地址获取经度值? - How to get latitude longitude value from an address in Google Maps? 如何使用Google Maps javascript获取搜索结果标记的纬度,经度 - How to get latitude, longitude of search result marker with google maps javascript 从Google地图行程中获取经度 - Get latitude longitude from google maps itinerary 如何从Google Maps V3 API获取经度和纬度? - How to get latitude and longitude from google maps v3 api? 如何将用户输入标记添加到我网站上的 Google 地图小部件,并从中获取纬度和经度数据? - How do I add a user-input marker to Google Maps widget on my website, and get the latitude and longitude data from it? 如何从函数获取纬度经度并将其发送到新的google.maps.LatLng(latitude,longitude)javascript - how to get latitude longitude from function and send it to new google.maps.LatLng( latitude ,longitude ) javascript 如何获取经度和纬度的谷歌在Javascript地图 - how to get longitude and latitude of google maps in javascript 使用jQuery插件的Google Maps API:如何在点击时获取标记的纬度和经度? - Google Maps API using jQuery Plugin: How to get a marker's latitude and longitude on click? 在InfoWindow中显示Google Maps标记的经度和纬度 - Displaying latitude and longitude of Google Maps marker in InfoWindow 在Google地图中按纬度/经度删除标记 - Removing marker by latitude/longitude in google maps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM