更改经纬度Google Maps API [英] Changing latitude and longitude google maps api

查看:58
本文介绍了更改经纬度Google Maps API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击链接时,我想更改地图的纬度和经度.当用户单击链接时,我试图要求maps.js,但它不起作用

I would like to change the latitude and longitude of the map when the user click in a link. I have tried to required maps.js when the user clicks on the link but it did not work

maps.js

function maps(){
  lats = 53.430967;
  longs = -2.960835;
  var mapProp = {
    center:new google.maps.LatLng(lats, longs),
    zoom: 17,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
}


module.exports = maps;

stadium.js

stadium.js

function stadium(){
  $( "a:contains('Stadium of Light')" ).on("click", function(){
    lats = 54.914740;
    longs = -1.388371;
    google.maps.event.addDomListener(window, 'load', maps);
    window.location.href='maps.html';
  });

推荐答案

您需要设置

概念证明小提琴

代码段:

var map;

function maps() {
  lats = 53.430967;
  longs = -2.960835;
  var mapProp = {
    center: new google.maps.LatLng(lats, longs),
    zoom: 17,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
  stadium();
}

function stadium() {
  $("a:contains('Stadium of Light')").on("click", function() {
    lats = 54.914740;
    longs = -1.388371;
    map.setCenter(new google.maps.LatLng(lats, longs));
  });
}
google.maps.event.addDomListener(window, "load", maps);

html,
body,
#googleMap {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}

<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#">Stadium of Light</a>
<div id="googleMap"></div>

这篇关于更改经纬度Google Maps API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆