Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinates not back to model #5

Closed
dacom-dark-sun opened this issue Nov 25, 2016 · 8 comments
Closed

Coordinates not back to model #5

dacom-dark-sun opened this issue Nov 25, 2016 · 8 comments

Comments

@dacom-dark-sun
Copy link

dacom-dark-sun commented Nov 25, 2016

I use example for back coordinates to model, but always receive a null. Code:

<?php echo $form->field($model, 'coordinates')->widget('\pigolab\locationpicker\CoordinatesPicker' , [
        'key' => 'my_key_here',
        'valueTemplate' => '{latitude},{longitude}' ,
        'options' => [
            'style' => 'width: 100%; height: 400px',  // map canvas width and height
        ] ,
        'searchBoxOptions' => [ // searchBox html attributes
            'style' => 'width: 300px;', // Optional , default width and height defined in css coordinates-picker.css
        ],
        'mapOptions' => [
            // google map options
            // visit https://developers.google.com/maps/documentation/javascript/controls for other options
        
            
        ],
      'clientOptions' => [
            'location' => [
                'latitude'  => 46.15242437752303 ,
                'longitude' => 2.7470703125,
            ],
            'radius'    => 300,
            'inputBinding' => [
                'latitudeInput'     => new JsExpression("$('#us2-lat')"),
                'longitudeInput'    => new JsExpression("$('#us2-lon')"),
                'radiusInput'       => new JsExpression("$('#us2-radius')"),
                'locationNameInput' => new JsExpression("$('#us2-address')")
            ]
]      
    ]);
?>
 

In model:
... { public $coordinates; .. ..
What problem can be here?

@pigochu
Copy link
Owner

pigochu commented Nov 26, 2016

Could you post your mysql table schema and model class source code ?

@dacom-dark-sun
Copy link
Author

dacom-dark-sun commented Dec 9, 2016

Im sorry for long answer, but actually it is my mistake with validation rules. Your widget words perfectly, but one question more:
How i can bind click event for get coordinates, that use not use drag and drop principle?

@pigochu
Copy link
Owner

pigochu commented Dec 10, 2016

@dacom-dark-sun

it's very easy, you can get the hidden input value

image

alert($('#locationpicker-coordinates').val() );

@pigochu
Copy link
Owner

pigochu commented Dec 10, 2016

@dacom-dark-sun

Oh . . I misunderstand what you mean

I need read jquery-locationpick or google map document how to do that

@pigochu
Copy link
Owner

pigochu commented Dec 10, 2016

Try it

    $js = '
    function(c){
        var map = jQuery(c).locationpicker("map").map;
        google.maps.event.addListener(map, "click", function(e) {
            var marker = jQuery(c).locationpicker("map").marker;
            var pos = e.latLng;
            jQuery(c).locationpicker("location" , {latitude: pos.lat(), longitude: pos.lng()});
            google.maps.event.trigger(marker, "dragend");
            // e.stopPropagation();
          });
    };

then in the CoordinatesPicker add oninitialized event

        'clientOptions' => [
            'addressFormat' => 'street_number',
            'radius'    => 300,
            'oninitialized' => new JsExpression($js),
        ],

@dacom-dark-sun
Copy link
Author

Ok, thank you very much!) i will try it ASAP..

Can i disable auto-render default location?
For.. not render any markers by default, but if user click or choice some place, model must receive coordinates.. Cause not every place need mark location from user, but if we have default position, this is can create some confusion..

@pigochu
Copy link
Owner

pigochu commented Dec 11, 2016

I think it possible ,

Options has a "markerVisible" can be set to false.

You can read all options from document http://logicify.github.io/jquery-locationpicker-plugin and try to implement your event.

@dacom-dark-sun
Copy link
Author

dacom-dark-sun commented Dec 11, 2016

Thanks a lot, i was solve it:
jQuery(c).locationpicker("map").marker.visible = true;
and load by default with false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants