Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改谷歌地图的位置_Javascript_Google Maps_Iframe_Maps - Fatal编程技术网

Javascript 更改谷歌地图的位置

Javascript 更改谷歌地图的位置,javascript,google-maps,iframe,maps,Javascript,Google Maps,Iframe,Maps,我想在我的网页上集成谷歌地图 我使用的方法是: <section id="contact" class="map"> <iframe width="100%" height="500px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&

我想在我的网页上集成谷歌地图

我使用的方法是:

<section id="contact" class="map">
        <iframe width="100%" height="500px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Twitter,+Inc.,+Market+Street,+San+Francisco,+CA&amp;aq=0&amp;oq=twitter&amp;sll=28.659344,-81.187888&amp;sspn=0.128789,0.264187&amp;ie=UTF8&amp;hq=Twitter,+Inc.,+Market+Street,+San+Francisco,+CA&amp;t=m&amp;z=15&amp;iwloc=A&amp;output=embed"></iframe>
 <br />
        <small>
           <!-- <a href="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Twitter,+Inc.,+Market+Street,+San+Francisco,+CA&amp;aq=0&amp;oq=twitter&amp;sll=28.659344,-81.187888&amp;sspn=0.128789,0.264187&amp;ie=UTF8&amp;hq=Twitter,+Inc.,+Market+Street,+San+Francisco,+CA&amp;t=m&amp;z=15&amp;iwloc=A"></a>-->
        </small>
        </iframe>
    </section>


这里是一个现场直播:

问题:如何将位置更改为其他位置。我的意思是,我可以从谷歌地图上的哪里选择位置并粘贴它,因为它位于src部分,以获得一个新位置

(例如,我想指向此位置:)


谢谢

您使用的iframe很难操作,您可以使用google maps api。 它的成本很高,您可以更改许多设置:

如果您想操纵地图,请不要使用该代码

下面是谷歌地图的基本示例代码

<!DOCTYPE html>
<html>

<head>

<title>Simple Map</title>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
  html, body, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var map;
function initialize() {
    var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(-34.397, 150.644)
 };
 map = new google.maps.Map(document.getElementById('map-canvas'),
  mapOptions);
 }

  google.maps.event.addDomListener(window, 'load', initialize);`

  </script>
  </head>
  <body>
     <div id="map-canvas"></div>
    </body>
 </html>

当你点击地图时,它会得到它的lat和lng

我也能实现这个代码。(对于上面的代码片段)如果你能给我一个方法让谷歌地图上的某个位置的LatLng工作,它将是警报(例如LatLng),这将是很有帮助的;但问题是我想在谷歌地图上搜索这个位置,然后从那里得到这个位置的lat和lng。但在上面的代码片段中,我必须手动拖动到该位置,然后单击,然后才能获得lat和lng(这非常痛苦)有没有一种直接的方法可以搜索和获取位置的lat lng?当我手动去该位置并复制lat和lng并将其粘贴到javascript中时,它没有突出显示我在javascript中提供的latlng,当我再次运行plunkr时,我只想在用户访问我的页面时突出显示位置。像这样,你可以在谷歌地图教程中找到更多的例子。你想在搜索后显示lat lng吗?简单到1+1。。在本例中查找搜索我不希望谷歌地图有任何动态行为。这对于我的用例来说是一次性的,所以如果有直接的方法
    google.maps.event.addListener(map, 'click', function(e) {
    alert(e.latLng());
    });