A widget for the Yii2 framework to render a Map with Google Maps and allow the user to pick a location on the map and get the coordinates.
A widget for the Yii2 framework to render a Map with Google Maps and allow the user to pick a location on the map and get the coordinates., (*1)
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist proximitymad/yii2-mapspicker-widget "1.0.*"
or add, (*4)
"proximitymad/yii2-mapspicker-widget": "1.0.*"
to the require section of your composer.json
file., (*5)
Once the extension is installed, simply use it in your code by :, (*6)
echo \app\components\widgets\Maps\MapPicker::widget([ 'apiKey'=>'gmaps-api-key' //required, 'search'=>'Madrid, Spain' //required ]);
<input name='lat' class='my-lat-field'/> <input name='lng' class='my-lng-field'/>
```php echo \app\components\widgets\Maps\MapPicker::widget([ 'apiKey'=>"my-api-key", 'width'=>'100%', 'height'=>300, 'search'=>"Barcelona, Spain", 'errorMsg'=>"Ey, your search didn't retrieve any results", 'latFieldClass'=>"my-lat-field" 'lngFieldClass'=>"my-lng-field" ]);, (*7)
### Example with search ### ```html <input name='search' class='my-search-field'/> <button class='my-button'>Search</button>
```php echo \app\components\widgets\Maps\MapPicker::widget([ 'apiKey'=>"my-api-key", 'width'=>'100%', 'height'=>300, 'search'=>"Barcelona, Spain", 'errorMsg'=>"Ey, your search didn't retrieve any results", 'searchField'=>[ 'inputClass'=>'my-search-field', 'buttonClass'=>'my-button' ] ]);, (*8)
## Events ## After a search or after picking a place on the map an event is triggered with the search results, the event is __mappicker-searchresults__. The results contains all the results and the components (country, state, province and locality). #### Example #### ```js $(document).on('mappicker-searchresults', function(evt, data){ console.log(data.results); console.log(data.components); })