首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌地图API3不返回地图?

谷歌地图API3不返回地图?
EN

Stack Overflow用户
提问于 2015-08-22 07:59:49
回答 1查看 59关注 0票数 0

我试着在谷歌地图上做标记,基于输入,但是地图没有显示任何数据?

这是我的例子

代码语言:javascript
复制
$(document).ready(function() {

    /* google maps */

    google.maps.visualRefresh = true;
    var geocoder = new google.maps.Geocoder();
    var mapOptions = {
        zoom: 14, // set the zoom level manually
        zoomControl: false,
        scaleControl: false,
        scrollwheel: false,
        disableDoubleClickZoom: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };


    var map;

    function initialize() {
        var address = $('#map').text(); /* change the map-input to your address */
        map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        if (geocoder) {
            geocoder.geocode({
                'address': address
            }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                        map.setCenter(results[0].geometry.location);

                        var infowindow = new google.maps.InfoWindow({
                            content: address,
                            map: map,
                            position: results[0].geometry.location,
                        });

                        var marker = new google.maps.Marker({
                            position: results[0].geometry.location,
                            map: map,
                            title: address
                        });

                    } else {
                        alert("No results found");
                    }
                }
            });
        }
    }
    google.maps.event.addDomListener(window, 'load', initialize);


});

代码语言:javascript
复制
<p id="map">
          Vojvode Dobrnjca, Belgrade
              </p>

<div id="map-canvas"></div>
EN

回答 1

Stack Overflow用户

发布于 2015-08-22 09:51:39

你错过了centermapOptions。您应该在geocoder函数中创建initialize变量。请参考。我给你看了地图。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32153811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档