0

KML ファイルを検索して、特定の住所がオーバーレイ内にあるかどうかを確認したいと考えています。現在、住所をジオコードに変換しています。ただし、この機能を追加するために必要なコードがわかりません。

現在のコードは次のとおりです。

function initialize() {
    var infowindow = new google.maps.InfoWindow({
        content: '',
        suppressMapPan:true
    });

    var myLatlng = new google.maps.LatLng(35.910200,-84.085100);   
        var myOptions = {
            zoom: 12,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

    var map = new google.maps.Map(
        document.getElementById("map_canvas"), myOptions);

    var d = new Date();    
    var n = d.getMilliseconds();
    var nyLayer = new google.maps.KmlLayer(
        'http://www.cspc.net/neighborhoods/groups.kml?rand=' + n,
        {  suppressInfoWindows: true, map: map});

    google.maps.event.addListener(nyLayer, 'click', function(kmlEvent) {    
        var url = kmlEvent.featureData.snippet;
        var groupName = kmlEvent.featureData.name;
        var insideContent = "<div style='width:250px;'><h2>" + groupName +
            "</h1><p>We have a neighborhood contact in your area! </p>" +
            "<p><a href='" + url + "' target='_blank'>Get connected!</a>" +
            " They look forward to hearing from you.</p><p>If you have " +
            "any additional questions, please contact our " +
            "<a href='http://www.cspc.net/communitylife' target='_blank'>" +
            "Community Life</a> staff for more information. Betsy Palk, " +
            "the Administrative Assistant, may be reached at:<br/><br/>" +
            "<b>Email:</b> <a href='mailto:betsypalk@cspc.net'>" +
            "betsypalk@cspc.net</a><br/><b>Phone:</b>  865-291-5268<p></div>";

        var clickPos = kmlEvent.latLng;
        var posX = new google.maps.LatLng(clickPos.lat(), clickPos.lng());
        infowindow.close();
        infowindow.setPosition(posX);
        infowindow.setContent(insideContent);
        infowindow.open(map);
    });

    eventMapClick = google.maps.event.addListener(map, 'click',
        function(event) {
            var marker = new google.maps.Marker({ position: event.latLng }); 
            var outsideContent = "<div style='width:250px;'><h2>Oops!</h1>" +
            "<p> It seems we don't have a neighborhood contact in your " +
            "area.</p><p>Please contact our <a " +
            "href='http://www.cspc.net/communitylife' target= '_blank'>" +
            "Community Life</a> staff for more information. " +
            "Betsy Palk, the Administrative Assistant, may be reached at:" +
            "<br/><br/><b>Email: </b> <a href='mailto:betsypalk@cspc.net'>" +
            "betsypalk@cspc.net</a><br/><b>Phone:</b>  865-291-5268<p></div>";

            infowindow.setContent(outsideContent);
            infowindow.open(map, marker);
        });
    }

    var geocoder = new google.maps.Geocoder();

    function searchAddress(address) {
        geocoder.geocode(
            {'address': address},
            function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    var loc = results[0].geometry.location;
                    // use loc.lat(), loc.lng()
                    window.alert(loc);
                }
                else {
                    window.alert("Not found: " + status);
                }
            }
        );
    };
4

1 に答える 1

0

あなたの質問が理解できれば、点 ( google.maps.LatLng) が KMLPlacemark定義 (: などの名前を付けたもの) の 1 つに含まれるかどうかを式で判断する必要があると思いますNeighborhood Group 1。each 内Placemarkで を定義し、Polygoneach 内での頂点を表す のPolygonセットを定義します。coordinatesPolygon

coordinates内のPolygonとを使用して、LatLngジオコーディングを介して取得すると、これらの数式から始めて、最適な数式を選択できます。

ここでも非常によく似た質問が SO で尋ねられました:ポリゴン内のマーカーの緯度経度を決定します。

于 2012-05-09T15:28:44.783 に答える