【问题标题】:how show result the autocomplete in the map in CodeIgniter Google Maps V3 API Library?如何在 CodeIgniter Google Maps V3 API 库中的地图中显示自动完成的结果?
【发布时间】:2015-08-22 11:59:00
【问题描述】:

我正在使用 CodeIgniter Google Maps V3 API 库 URL 在我的表单中选择位置。所以我的控制器如下:

$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
$config['places'] = TRUE;
$config['placesAutocompleteInputID'] = 'event_location';
$config['placesAutocompleteBoundsMap'] = TRUE; // set results biased towards the maps viewport
$config['placesAutocompleteOnChange'] = 'alert(\'You selected a place\');';

$this->googlemaps->initialize($config);

view 是:

<div class="form-group">
    <label class="col-md-3 col-xs-12 control-label">Select Venue in google map</label>
    <div class="col-md-6 col-xs-12">                                                                                                                                     
        <?php 
            $google_map_date = array(
              'name'        => 'event_location',
              'type'        => 'text',
              'id'          => 'event_location',
              'class'       => 'form-control',
            );

        ?>
        <?php echo form_input($google_map_date);?>
        <span class="help-block"></span>                                        
    </div>
    <div class="col-md-12 col-xs-12">    
        <?php echo $map['html']; ?>
    </div>
</div>

虽然我可以自动选择位置,但地图并未显示所选位置。我应该编写什么代码来显示所选位置,而不仅仅是提醒You selected a place

【问题讨论】:

  • 好像这个问题Link

标签: codeigniter google-maps google-maps-api-3


【解决方案1】:

以下是工作示例:

$config['placesAutocompleteOnChange'] = "

        markers_map[0].setVisible(false);
        var place = placesAutocomplete.getPlace();
        if (!place.geometry) {
          return;
        }

        // If the place has a geometry, then present it on a map.
        if (place.geometry.viewport) {
          map.fitBounds(place.geometry.viewport);
          map.setZoom(15);
        } else {
          map.setCenter(place.geometry.location);
          map.setZoom(15);
        }

        markers_map[0].setPosition(place.geometry.location);
        markers_map[0].setVisible(true);

        var address = '';
        if (place.address_components) {
          address = [
            (place.address_components[0] && place.address_components[0].short_name || ''), (place.address_components[1] && place.address_components[1].short_name || ''), (place.address_components[2] && place.address_components[2].short_name || '')
          ].join(' ');
        }

        ";

【讨论】:

    猜你喜欢
    • 2012-08-09
    • 2012-06-06
    • 2014-07-03
    • 2018-01-24
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    相关资源
    最近更新 更多