Javascript 使用Google Api设置纬度和经度参数
我开始接触javascript、api等。我试图在一些javascript中使用GoogleMapsAPI,所以我的主要想法是创建带有存储的纬度和经度值的按钮来显示在地图中,但是我很难传递参数 这是到目前为止我的代码Javascript 使用Google Api设置纬度和经度参数,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我开始接触javascript、api等。我试图在一些javascript中使用GoogleMapsAPI,所以我的主要想法是创建带有存储的纬度和经度值的按钮来显示在地图中,但是我很难传递参数 这是到目前为止我的代码 函数加载(){ var mapOpt={ 中心:新google.maps.LatLng(0.0,0.0), 缩放:5, mapTypeId:google.maps.mapTypeId.ROADMAP }; var map=new google.maps.map(document.
函数加载(){
var mapOpt={
中心:新google.maps.LatLng(0.0,0.0),
缩放:5,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“googleMap”),mapOpt);
正如您所看到的,我正在尝试将存储的lat和lng传递给函数,我如何才能做到这一点?如果您希望您的函数将提供不同的位置,那么我认为它将需要一个参数
函数加载(lat,lng)
,然后中心:新的google.maps.LatLng(lat,lng),
参考:你不能这样做吗:
function initialize()
{
myLatLng = new google.maps.LatLng(37.422104808,-122.0838851);
var geoLatLongCoordinates;
var lat = 37.422104808;
var lng = -122.0838851;
var zoom = 18;
var maptype = google.maps.MapTypeId.ROADMAP;
if (!isNaN(lat) && !isNaN(lng))
{
myLatLng = new google.maps.LatLng(lat, lng);
}
var myOptions = {zoom: zoom,center: myLatLng,mapTypeId: maptype};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
您如何“尝试将存储的lat和lng传递到功能”?存储的lat和lng是什么?
function initialize()
{
myLatLng = new google.maps.LatLng(37.422104808,-122.0838851);
var geoLatLongCoordinates;
var lat = 37.422104808;
var lng = -122.0838851;
var zoom = 18;
var maptype = google.maps.MapTypeId.ROADMAP;
if (!isNaN(lat) && !isNaN(lng))
{
myLatLng = new google.maps.LatLng(lat, lng);
}
var myOptions = {zoom: zoom,center: myLatLng,mapTypeId: maptype};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}