ashcanschool
ashcanschool

Reputation: 327

Logicify jQuery Location Picker Plugin - Programatically Setting Location

This is dealing with Logicify's Location Picker plugin for jQuery, I'm having an issue attempting to programmatically set the map location.

This questions has been asked a few times without an answer: Logicify Location picker using dynamic change for input https://github.com/Logicify/jquery-locationpicker-plugin/issues/20

Essentially I would assume that I could programmatically set the values of latitude and/or longitude and the plugin would respond as if I had typed those values in (through the inputBinding latitude and longitude 'on('change' functions). However it doesn't.

HTML

<label for="lat">Latitude</label>
<input name="lat" id="lat" value="56.47073634828131" />

<label for="long">Longitude</label> 
<input name="long" id="long" value="-2.982454299926758" />

<input type="hidden" id="address" />
<input type="hidden" id="radius" />

<div id="map" style="height: 250px;"></div>

JS

$('#map').locationpicker({
    location: {latitude: $('#lat').val(), longitude: $('#long').val()},
    radius: 0,
    zoom: 9,
    inputBinding: {
        latitudeInput: $('#lat'),
        longitudeInput: $('#long')
    },
    enableAutocomplete: true
});

If I type in the value it will change, however if I use something like:

$('#lat').val('55.859028119431926');
$('#long').val('-4.234895706176758');

I've tried various attempts at calling .locationpicker() after resetting the values or .trigger() on the values themselves. I'm not sure how to proceed if I can't get the inputBindings within the plugin to fire.

Can anyone steer me in a direction to get the inputBinding functions to pick up on programmatically setting the lat and long?

I'm hoping that I haven't committed a faux pas here rehashing a question that has not been answered.

Upvotes: 1

Views: 2703

Answers (1)

Vaibhav K
Vaibhav K

Reputation: 388

Try

$('#map').locationpicker("location", {latitude: 55.859028119431926, longitude: -4.234895706176758});

Upvotes: 9

Related Questions