【问题标题】:how can I pass the Google API Key for google.maps.Geocoder().geocode()如何传递 google.maps.Geocoder().geocode() 的 Google API 密钥
【发布时间】:2018-10-10 17:30:15
【问题描述】:

请为我提供以下代码的正确解决方案

如何传递 Google API 密钥

function load_map_from_address(mapid, address) {
        // check if gps has been locally cached.     
        geocoder = new google.maps.Geocoder();
        //alert(geocoder);
        var geocoderAPIKey = 'geocoderAPIKey ';
        geocoder.geocode({ 'address': address }, function (results, status) {
            //alert(status);
            if (status == "OK") {

                var gps = results[0].geometry.location;
                create_map(gps.lat(), gps.lng(), mapid);
            }
            else {
                $('#' + mapid).html('<div class="map_canvas_text "><h4>address not found</h4></div>').show();

            }
        });
    }

【问题讨论】:

    标签: javascript asp.net google-maps


    【解决方案1】:

    您可以在包含 Google 地图 js 时提及它。就像是 。

    Google 地图路径 js?key=yourApiKey

    在你的脚本标签中

    【讨论】:

    • 我想添加相同的函数 geocoder.geocode({ 'address': address }, function (results, status) 有什么方法可以添加吗?@Taylor
    • @HardikMasalawala 我不这么认为。如果有什么办法..谷歌不会建议用JS文件路径添加它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 2013-03-21
    • 2023-03-14
    相关资源
    最近更新 更多