根据自动完成输入使用google maps codeigniter库更改地图的中心 [英] Change center of map according to autocomplete input using google maps codeigniter library

查看:171
本文介绍了根据自动完成输入使用google maps codeigniter库更改地图的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用google maps codeigniter库的placesautocompleteonchange时,我在获取地图中心时遇到困难。



首先,随着网页加载,的地图设置为特定的城市(我指定的)
$ config ['center'] ='8.457348645837307,124.63308727385254';



然后我指定一些配置来激活自动完成功能。

 `$ config [ places'] = TRUE; 
$ config ['placesAutocompleteInputID'] ='address';
$ config ['placesAutocompleteBoundsMap'] = TRUE;`

配置

 `$ marker = array(); 
$ marker ['draggable'] = true;`

不知道如何根据输入字段中输入的地址更改地图的中心,并根据地图的当前中心更改标记的位置。



我希望有人可以帮助我。



PS:我使用Sir BIOSTALL的Google Maps V3 Codeigniter Library

解决方案

需要使用 $ this-> input-> post(),然后将两个值与 explode 组合到一个字符串



有关更多帮助,请阅读


  1. http://www.codeigniter.com/user_guide/

  2. http://biostall.com/demos/google-maps-v3-api-codeigniter- library / placesautocomplete






  $ center = implode(',',array(
$ this-> input-> post('lat'),
$ this-> input-> post('lon')
));

$ config ['center'] = $ center;
$ marker ['position'] = $ center;


I am having difficulties on getting the center of the map when I use 'placesautocompleteonchange' of google maps codeigniter library.

First, as the page loads, the center of the map is set to a specific city (which is I specified) $config['center'] = '8.457348645837307,124.63308727385254';

then I specified some configurations to activate autocomplete function.

   `$config['places'] = TRUE;
    $config['placesAutocompleteInputID'] = 'address';
    $config['placesAutocompleteBoundsMap'] = TRUE;`

then I also add a marker configuration

    `$marker = array();
    $marker['draggable'] = true;`

my problem is, I don't know how to change the center of the map according to the inputted address on my input field and change the location of the marker according to the current center of the map.

I hope someone can help me. thank you

(sorry for my bad english)

P.S: I used Sir BIOSTALL's Google Maps V3 Codeigniter Library

解决方案

You simply need to get the input using $this->input->post() and then combine both values with explode into a string

For more assistance please read

  1. http://www.codeigniter.com/user_guide/
  2. http://biostall.com/demos/google-maps-v3-api-codeigniter-library/placesautocomplete


$center = implode(',', array(
     $this->input->post('lat'),
     $this->input->post('lon')
));

$config['center'] = $center;
$marker['position'] = $center;

这篇关于根据自动完成输入使用google maps codeigniter库更改地图的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆