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

errors in javascitps #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/validator/sfValidatorGeocodedAddress.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class sfValidatorGeocodedAddress extends sfValidatorBase
{
protected function configure($options = array(), $messages = array())
{
$this->setMessage('invalid', 'Address "%address%" could not be geolocated with google maps');
}

/**
* @see sfValidatorBase
*/
protected function doClean($value)
{
$map = new GMap();
$address = new GMapGeocodedAddress($value);
if($address->geocode($map->getGMapClient()))
{
return $value;
}

throw new sfValidatorError($this, 'invalid',array('address'=>$value));
}
}
6 changes: 3 additions & 3 deletions web/js/sfEasyGMapPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ var set_location = function(response, status)
marker.gps_precision = zoom;
//console.log('position settée ' + marker.google_position);

marker.set_position(point);
map.set_zoom(zoom);
map.set_center(point);
marker.setPosition(point);
map.setZoom(zoom);
map.setCenter(point);
}

var geocode_and_show = function (address)
Expand Down
6 changes: 4 additions & 2 deletions web/js/sfEasyGMapPlugin.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
var moveToMarker = function ()
{
var darwin = new google.maps.LatLng(-12.461334, 130.841904);
map.set_zoom(13);
map.set_center(darwin);
map.setZoom(13);
map.setCenter(darwin);

gmapSample_AddConsoleLine("You just click on Darwin's marker !");
}
Expand Down Expand Up @@ -34,6 +34,8 @@ var gmapSample_AddConsoleLine = function (content)
var line = '<div class="line">' + time + ' <span class="begin-line">></span>' + content + '</div>';

console.innerHTML = inner_console + line;



return false;
}
64 changes: 64 additions & 0 deletions web/js/sspEasyGMapPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var update_form_data = function()
{
$('.gmap_address').val(marker.google_position);
$('.gmap_lng').html(this.position.lng());
//$('#sf_guard_user_gps_precision').val(this.gps_precision);
//console.log('position lue ' + marker.google_position);
$('.gmap_lat').html(this.position.lat());
}

var set_clicked_location = function(response, status)
{
if(status != google.maps.GeocoderStatus.OK)
{
alert('Oops... adress not recognized by Google !');
return false;
}

var zoom=15;
//console.log(response[0].geometry);
//console.log(response[0].geometry.location_type);
switch(response[0].geometry.location_type)
{
// country level
case google.maps.GeocoderLocationType.APPROXIMATE:
zoom=9;
break;
case google.maps.GeocoderLocationType.GEOMETRIC_CENTER:
zoom=11;
break;
// city level
case google.maps.GeocoderLocationType.RANGE_INTERPOLATED:
zoom=13;
break;
case google.maps.GeocoderLocationType.ROOFTOP:
zoom=14;
break;
default:
zoom=14;
break;
}

point = response[0].geometry.location;
//console.log(point);

if (typeof marker == 'undefined')
{
marker = new google.maps.Marker({'map': map, draggable: true});
google.maps.event.addListener(marker, 'position_changed', update_form_data)
}
marker.google_position = response[0].formatted_address;
marker.gps_precision = zoom;

marker.setPosition(point);
marker.setVisible(true);
//map.setZoom(zoom);
//map.setCenter(point);
}

var geocode_clicked = function (event)
{
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'location': event.latLng}, set_clicked_location);
}