admin管理员组文章数量:1405617
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
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';
});
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
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';
});
Share
Improve this question
asked Mar 19, 2016 at 22:07
SquexisSquexis
971 gold badge4 silver badges12 bronze badges
1 Answer
Reset to default 5You need to set the center
property of the google.maps.Map object.
function stadium() {
$("a:contains('Stadium of Light')").on("click", function() {
lats = 54.914740;
longs = -1.388371;
map.setCenter(new google.maps.LatLng(lats,longs));
});
}
proof of concept fiddle
code snippet:
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./maps/api/js"></script>
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#">Stadium of Light</a>
<div id="googleMap"></div>
本文标签: javascriptChanging latitude and longitude google maps apiStack Overflow
版权声明:本文标题:javascript - Changing latitude and longitude google maps api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744910268a2631872.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论