• <i id='sV92Y'><tr id='sV92Y'><dt id='sV92Y'><q id='sV92Y'><span id='sV92Y'><b id='sV92Y'><form id='sV92Y'><ins id='sV92Y'></ins><ul id='sV92Y'></ul><sub id='sV92Y'></sub></form><legend id='sV92Y'></legend><bdo id='sV92Y'><pre id='sV92Y'><center id='sV92Y'></center></pre></bdo></b><th id='sV92Y'></th></span></q></dt></tr></i><div id='sV92Y'><tfoot id='sV92Y'></tfoot><dl id='sV92Y'><fieldset id='sV92Y'></fieldset></dl></div>

  • <legend id='sV92Y'><style id='sV92Y'><dir id='sV92Y'><q id='sV92Y'></q></dir></style></legend>

      <tfoot id='sV92Y'></tfoot>

      <small id='sV92Y'></small><noframes id='sV92Y'>

        • <bdo id='sV92Y'></bdo><ul id='sV92Y'></ul>

        需要从谷歌地图API获取纬度和经度

        时间:2023-09-06
        <tfoot id='DyrAS'></tfoot>

        • <i id='DyrAS'><tr id='DyrAS'><dt id='DyrAS'><q id='DyrAS'><span id='DyrAS'><b id='DyrAS'><form id='DyrAS'><ins id='DyrAS'></ins><ul id='DyrAS'></ul><sub id='DyrAS'></sub></form><legend id='DyrAS'></legend><bdo id='DyrAS'><pre id='DyrAS'><center id='DyrAS'></center></pre></bdo></b><th id='DyrAS'></th></span></q></dt></tr></i><div id='DyrAS'><tfoot id='DyrAS'></tfoot><dl id='DyrAS'><fieldset id='DyrAS'></fieldset></dl></div>
            <tbody id='DyrAS'></tbody>

            <small id='DyrAS'></small><noframes id='DyrAS'>

              <legend id='DyrAS'><style id='DyrAS'><dir id='DyrAS'><q id='DyrAS'></q></dir></style></legend>
                <bdo id='DyrAS'></bdo><ul id='DyrAS'></ul>

                  本文介绍了需要从谷歌地图API获取纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  https://developers.google.com/maps/documentation/javascript/examples/places-searchbox

                  我正在使用从上面的链接获得的地图.它在我的网站上运行良好.当我搜索一个地方时,该位置将显示在地图中.我需要得到它的经度和纬度,当我点击谷歌地图上的一个地方时,它应该显示在一个文本框中.

                  I'm using the map which I got from above link. It works fine in my website. When I search for a place ,that location will be shown in map. I need to get its longitude and latitude and should be displayed in a textbox when I click on a place on Google map.

                  代码如下所示

                  <!DOCTYPE html>
                  <html>
                    <head>
                      <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
                      <meta charset="utf-8">
                      <style>
                        html, body {
                          height: 100%;
                          margin: 0;
                          padding: 0;
                        }
                        #map {
                          height: 100%;
                        }
                  .controls {
                    margin-top: 10px;
                    border: 1px solid transparent;
                    border-radius: 2px 0 0 2px;
                    box-sizing: border-box;
                    -moz-box-sizing: border-box;
                    height: 32px;
                    outline: none;
                    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
                  }
                  
                  #pac-input {
                    background-color: #fff;
                    font-family: Roboto;
                    font-size: 15px;
                    font-weight: 300;
                    margin-left: 12px;
                    padding: 0 11px 0 13px;
                    text-overflow: ellipsis;
                    width: 300px;
                  }
                  
                  #pac-input:focus {
                    border-color: #4d90fe;
                  }
                  
                  .pac-container {
                    font-family: Roboto;
                  }
                  
                  #type-selector {
                    color: #fff;
                    background-color: #4d90fe;
                    padding: 5px 11px 0px 11px;
                  }
                  
                  #type-selector label {
                    font-family: Roboto;
                    font-size: 13px;
                    font-weight: 300;
                  }
                  
                      </style>
                      <title>Places Searchbox</title>
                      <style>
                        #target {
                          width: 345px;
                        }
                      </style>
                    </head>
                    <body>
                      <input id="pac-input" class="controls" type="text" placeholder="Search Box">
                      <div id="map"></div>
                      <script>
                  // This example adds a search box to a map, using the Google Place Autocomplete
                  // feature. People can enter geographical searches. The search box will return a
                  // pick list containing a mix of places and predicted search terms.
                  
                  function initAutocomplete() {
                    var map = new google.maps.Map(document.getElementById('map'), {
                      center: {lat: -33.8688, lng: 151.2195},
                      zoom: 13,
                      mapTypeId: google.maps.MapTypeId.ROADMAP
                    });
                  
                    // Create the search box and link it to the UI element.
                    var input = document.getElementById('pac-input');
                    var searchBox = new google.maps.places.SearchBox(input);
                    map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
                  
                    // Bias the SearchBox results towards current map's viewport.
                    map.addListener('bounds_changed', function() {
                      searchBox.setBounds(map.getBounds());
                    });
                  
                    var markers = [];
                    // [START region_getplaces]
                    // Listen for the event fired when the user selects a prediction and retrieve
                    // more details for that place.
                    searchBox.addListener('places_changed', function() {
                      var places = searchBox.getPlaces();
                  
                      if (places.length == 0) {
                        return;
                      }
                  
                      // Clear out the old markers.
                      markers.forEach(function(marker) {
                        marker.setMap(null);
                      });
                      markers = [];
                  
                      // For each place, get the icon, name and location.
                      var bounds = new google.maps.LatLngBounds();
                      places.forEach(function(place) {
                        var icon = {
                          url: place.icon,
                          size: new google.maps.Size(71, 71),
                          origin: new google.maps.Point(0, 0),
                          anchor: new google.maps.Point(17, 34),
                          scaledSize: new google.maps.Size(25, 25)
                        };
                  
                        // Create a marker for each place.
                        markers.push(new google.maps.Marker({
                          map: map,
                          icon: icon,
                          title: place.name,
                          position: place.geometry.location
                        }));
                  
                        if (place.geometry.viewport) {
                          // Only geocodes have viewport.
                          bounds.union(place.geometry.viewport);
                        } else {
                          bounds.extend(place.geometry.location);
                        }
                      });
                      map.fitBounds(bounds);
                    });
                    // [END region_getplaces]
                  }
                  
                  
                      </script>
                      <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAkwr5rmzY9btU08sQlU9N0qfmo8YmE91Y&libraries=places&callback=initAutocomplete"
                           async defer></script>
                    </body>
                  </html>
                  

                  推荐答案

                  places.forEach(function(place) {
                  console.log("lat: "+place.geometry.location.lat()+" lng: "+place.geometry.location.lng())
                  //etc
                  

                  这篇关于需要从谷歌地图API获取纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:通过大量纬度/经度坐标优化搜索以找到匹配项 下一篇:Google maps API - 客户当前位置的中心地图

                  相关文章

                  最新文章

                    <i id='pSe7o'><tr id='pSe7o'><dt id='pSe7o'><q id='pSe7o'><span id='pSe7o'><b id='pSe7o'><form id='pSe7o'><ins id='pSe7o'></ins><ul id='pSe7o'></ul><sub id='pSe7o'></sub></form><legend id='pSe7o'></legend><bdo id='pSe7o'><pre id='pSe7o'><center id='pSe7o'></center></pre></bdo></b><th id='pSe7o'></th></span></q></dt></tr></i><div id='pSe7o'><tfoot id='pSe7o'></tfoot><dl id='pSe7o'><fieldset id='pSe7o'></fieldset></dl></div>
                    1. <tfoot id='pSe7o'></tfoot>
                        <bdo id='pSe7o'></bdo><ul id='pSe7o'></ul>

                      <legend id='pSe7o'><style id='pSe7o'><dir id='pSe7o'><q id='pSe7o'></q></dir></style></legend>

                      <small id='pSe7o'></small><noframes id='pSe7o'>