2016-08-11 16 views
-1

結果が返ってくると、次のコードで結果の完全なアドレスコンポーネントが取得されないように見えます。これは他のサービスでさまざまなことを判断するために使用しています。Googleで境界線付きのジオコーディング

私が範囲を取るとすぐに、それはうまく動作します。しかし、私はまだそれを限界に限定して必要としています。

これはなぜですか?どのように問題を解決することができますか?

CODE:

_geocoder.geocode(_.extend(position, { 
       bounds: { 
        west: -25.806884999999966, 
        east: 16.380615000000034, 
        south: 48.98742739340465, 
        north: 60.16884190739975 
       } 
      }), function (results, status) { 
       if (status === google.maps.GeocoderStatus.OK) { 
        _lastResults = results; 

        deferred.resolve(results); 
       } else { 
        deferred.reject('Geocode was not successful for the following reason: ' + status); 
       } 
      }); 
+0

[MCVE]問題を実証しているしてください。失敗した実際のコール(または失敗したコールのサンプル) '_.extend'はどこから来たのでしょうか?それは何を期待していますか? (提供されたスニペットに構文エラーがあるように見えます) – geocodezip

答えて

0

GeocoderRequestに境界を追加するには、それは要求オブジェクト内部に入る:しかし

var data = { 
    bounds: { 
    west: -25.806884999999966, 
    east: 16.380615000000034, 
    south: 48.98742739340465, 
    north: 60.16884190739975 
    } 
}; 
var bounds = new google.maps.LatLngBounds(
       new google.maps.LatLng(data.bounds.south, data.bounds.west), 
       new google.maps.LatLng(data.bounds.north, data.bounds.east)); 

geocoder.geocode({ 
    address: "London", 
    bounds: bounds 
}, function(results, status) { 
    if (status === google.maps.GeocoderStatus.OK) { 
    var marker = new google.maps.Marker({ 
     position: results[0].geometry.location, 
     map: map 
    }); 
    } else { 
    alert('Geocode was not successful for the following reason: ' + status); 
    } 
}); 

オプションのパラメータ:

境界 - ジオコード結果をより顕著に偏らせるLatLngBounds。 boundsパラメータは、ジオコーダの結果にのみ影響し、完全に制限することはありません。

proof of concept fiddle

をコードスニペット(詳細は下記のビューポートのバイアスをご覧ください。):

function initialize() { 
 
    var map = new google.maps.Map(
 
    document.getElementById("map_canvas"), { 
 
     center: new google.maps.LatLng(37.4419, -122.1419), 
 
     zoom: 13, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }); 
 
    var data = { 
 
    bounds: { 
 
     west: -25.806884999999966, 
 
     east: 16.380615000000034, 
 
     south: 48.98742739340465, 
 
     north: 60.16884190739975 
 
    } 
 
    }; 
 
    var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(data.bounds.south, data.bounds.west), new google.maps.LatLng(data.bounds.north, data.bounds.east)); 
 
    var rectangle = new google.maps.Rectangle({ 
 
    map: map, 
 
    bounds: bounds 
 
    }); 
 
    map.fitBounds(bounds); 
 
    var geocoder = new google.maps.Geocoder(); 
 
    geocoder.geocode({ 
 
    address: "London", 
 
    bounds: bounds 
 
    }, function(results, status) { 
 
    if (status === google.maps.GeocoderStatus.OK) { 
 
     var marker = new google.maps.Marker({ 
 
     position: results[0].geometry.location, 
 
     map: map 
 
     }); 
 
    } else { 
 
     alert('Geocode was not successful for the following reason: ' + status); 
 
    } 
 
    }); 
 
} 
 
google.maps.event.addDomListener(window, "load", initialize);
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<div id="map_canvas"></div>

+0

境界が正常に機能しています。問題は、同じ検索で境界がある場合に 'address_components'配列内の戻り値が少なくなります。 'address_components'の – DrogoNevets

+0

あなたの質問にあなたの問題を明確にしてください。 – geocodezip

関連する問題