This won't be exactly what you're after, but I have recently implemented
something quite similar. The following (1.3 code) will allow the user to drag
and drop a pin to change the lat/long of that pin on the fly.
View
The first thing you'll need is to do is add a couple of json properties when
you're defining each of your markers in your view, for example:
var marker = new google.maps.Marker({
...
callbackUrl:
"http://www.yoursite.com/<controller>/<action>/<id>",
draggable: true
});
Then you'll need to add an event listener to listen for the "dragend" event of
the pin:
// Add a "dragend" event listener so that we can determine the lat/long
of the drop point
google.maps.event.addListener(marker, "dragend", function() {
var position = marker.getPosition();
var _data = "latitude=" + position.lat() + "&longitude=" +
position.lng();
$.ajax({
type: "POST",
url: marker.callbackUrl,
data: _data,
success: function(data) {
// Do some stuff to notify the user that the
lat/long has been updated
}
});
});
Controller
In your callback action within your controller, you'll need something like this:
function <action>($id = null) {
$this->autoRender = false;
if ($this->RequestHandler->isAjax()) {
Configure::write('debug', 0);
$this->layout = 'ajax';
$data['<Model>']['id'] = $id;
// Build up the data based on the posted form values
foreach($this->params['form'] as $key => $value) {
$data['<Model>'][$key] = $value;
}
// Save the data
if (!$this-><Model>->save($data)) {
$this->log($data, 'error');
$this->log($this-><Model>->validationErrors,
'error');
$this->set('message', 'There was an error
updating the location for <b>' . $<model>['<Model>']['name'] . '</b>');
$this->render('/elements/flash/error', 'ajax');
} else {
$this->set('message', 'The location for <b>' .
$<model>['<Model>']['name'] . '</b> has been updated');
$this->render('/elements/flash/success',
'ajax');
}
}
}
Like I said, I know this isn't exactly what you're after, but hopefully it will
be of some use to you.
Keith Gorman
Class Outfit
[email protected]
www.classoutfit.com
On 30 Apr 2012, at 05:13, Michael Gaiser wrote:
So, I want to use Google maps on my project which makes use of a
Location model. In that model there is a longitude and latitude value.
Most of the tutorials I have looked at talk about how to place
markers on your map. What I want to do is use the map to allow people
to navigate to the location they are editing and set the longitude and
latitude based on the current center of the map giving an easy
interface for entering in such values. So it leads me to this
question: How do I get the long/lat values from the google map and
save those values to my database? Thanks.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php