谷歌地图:根据国家名称或ISO显示地图

时间:2015-02-09 07:28:23

标签: javascript google-maps-api-3

只是尝试一些有趣的事情。

在我的数据库中,我将国家/地区作为名称和iso - 我想将geocode()与其中一个称为geocode()并获得该区域的固定。

    var country_name = $('div#start-country-name').data('countryname');
    var location_coord = $('div#start-location-coord').data('locationcoord'); // array of locations in that country

    var map;
    var geocoder;
    var marker;

    function initialize() {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
            zoom: 6,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("view-the-map"),myOptions);
    }

initialize();

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

可悲的是,它只显示 - 空白 所有都是aso。

任何想法或指向正确的方向。

0 个答案:

没有答案