1

我想要一个标记的信息窗口内容,如下所示

替代文字

到目前为止我的代码是

loadEmbeddedMap : function() {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initEmbeddedMap";
        document.body.appendChild(script)
    },
    initEmbeddedMap : function() {
        var myLatlng = new google.maps.LatLng(40, -80);
        var myOptions = {
                zoom: 8,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById("embeddedGoogleMap"), myOptions);
        geocoder = new google.maps.Geocoder();
        geocoder.geocode( { 'address': $('#userMapAddress').val()}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                marker = new google.maps.Marker({
                    map: map, 
                    position: results[0].geometry.location
                });
                console.debug(results[0]);
                infowindow = new google.maps.InfoWindow();
                var infoWindowContent = "<div><strong>Address:</strong></div>";
                infoWindowContent    += "<div>"+results[0].address_components[0].short_name+","+results[0].address_components[1].short_name+"</div>";
                infoWindowContent    += "<div>"+results[0].address_components[5].short_name+","+results[0].address_components[7].short_name+"</div>";
                //infoWindowContent    += results[0].formatted_address;
                infowindow.setContent(infoWindowContent);
                infowindow.open(map, marker);
            } else {
                //alert("Geocode was not successful for the following reason: " + status);
            }
        });
        $('#embeddedGoogleMapWrapper').show();
    },

上面的代码输出这个

替代文字

如何获得那些'方向','搜索附近'的东西......?任何帮助表示赞赏..

4

1 回答 1

2

我会从阅读开始

http://code.google.com/apis/maps/documentation/localsearch/devguide.html#hiworld

正如我所看到的,可以做你想做的事。我不能给你一个直接的答案,但也许是一个线索。我会在 infowindow 中创建自己的表单,至少非常接近原始的 google 表单,并通过发送这些搜索查询来处理点击事件。比你需要处理搜索结果

http://code.google.com/apis/maps/documentation/localsearch/devguide.html#handle_search_results

做一些测试

http://code.google.com/apis/ajax/playground/#the_hello_world_of_local_search

例如,您可以从 localSearch.results[i].lat 等获取 lat。

我希望你能从中得到一些东西

于 2011-03-16T11:38:35.923 回答