使用gmaps api中的参数调用函数initmap [英] Call function initmap with parameters in gmaps api

查看:526
本文介绍了使用gmaps api中的参数调用函数initmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能,google map api tutorial的默认功能,我刚刚加了2个参数latt和lngg。

I have this function, the default function from google maps api tutorial, I have just added 2 parameters latt and lngg.

function initMap(latt,lngg) {


    var uluru = {lat: latt , lng: lngg};
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      center: uluru
    });
    var marker = new google.maps.Marker({
      position: uluru,
      map: map
    });
  }

我想称之为他们称之为:

And I want to call it like they call it :

<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAmjE35Pm1eDdyF6Vg3WC69opkqLIVt3GY&callback=initMap">
</script>

但每次使用不同的参数,因为我将拥有6000个地图,并且我想调用脚本对于每个函数

but using different parameters each time, because I will have 6000 maps, and I want to call the script for each function

我不知道是否可以使用& callback = initMap(latt,lngg)。

I don't know if something like &callback=initMap(latt,lngg) is possible.

非常感谢你

Thank you so much

推荐答案

你可以有一个单独的脚本来设置变量,然后使用initMap )调用这些变量。

You could have a separate script which sets the variables, and then have the initMap() call these variables.

var latt;
var lngg;

function setCoords(latt,lngg){
  this.latt = latt;
  this.lngg = lngg;
}

function initMap() {

    var uluru = {lat: latt , lng: lngg};
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      center: uluru
    });
    var marker = new google.maps.Marker({
      position: uluru,
      map: map
    });
  }

<script type ='text/javascript'>setCoords(33.225488,-111.5955)</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAmjE35Pm1eDdyF6Vg3WC69opkqLIVt3GY&callback=initMap">
</script>

这篇关于使用gmaps api中的参数调用函数initmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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