This is a different version of editpics.php. The difference is that instead of double-clicking to get the coordinate value, you drag the marker to the destination. The nice thing about this is that the coordinate values show up immediately, rather than after you submit the form.
FIND:
define('EDITPICS_PHP', true);
ADD:
define('GMAP_PHP', true);
define('REGISTER_PHP', true);
FIND:
$THUMB_ROWSPAN=5;
REPLACE with:
$THUMB_ROWSPAN=6;
FIND:
array($CONFIG['user_field4_name'], 'user4', 0, 255),
after it, ADD:
array($lang_gmap_php['coordinates'], 'coordinates', 10, 255, 'latitude', 'longitude'),
FIND:
$user4 = get_post_var('user4', $pid);
after it, ADD:
$coordinates = get_post_var('coordinates', $pid);
FIND:
$update .= ", user4 = '".addslashes($user4)."'";
after it, ADD:
$coordinates = explode(',',$coordinates);
$latitude = $coordinates[0];
$longitude = $coordinates[1];
$update .= ", latitude = '".addslashes($latitude)."'";
$update .= ", longitude = '".addslashes($longitude)."'";
FIND:
$isgalleryicon_disabled = ($CURRENT_PIC['category'] < FIRST_USER_CAT) ? 'disabled="disabled" ':'';
AFTER it, ADD:
global $CONFIG, $pid, $map_key, $default_center_coord, $default_zoom_level, $map_code, $coordinates, $lang_register_php, $lang_gmap_php, $version;
$pid = $CURRENT_PIC['pid'];
$coordinates = $latitude . ',' . $longitude;
$map_key = $CONFIG['gmap_api_key'];
$use_dev_version = $CONFIG['gmap_version'];
// if version config is set not to use development version, use 2 (current stable), otherwise, use 2.x (latest development)
if ($use_dev_version == 1) {
$version = '2.x';
} else {
$version = '2';
}
$default_zoom_level = $CONFIG['gmap_default_zoom'];
//Google Maps API mysql fun
$query = "SELECT *
FROM {$CONFIG['TABLE_PICTURES']}
WHERE
{$CONFIG['TABLE_PICTURES']}.pid = {$pid}
LIMIT 1;
";
$result = cpg_db_query($query);
if($row = mysql_fetch_array($result))
{
$CURRENT_PIC = $row; //send a copy to get_pic_url it messes with the vars
$latitude = $row['latitude'];
$longitude = $row['longitude'];
// by default, the center coordinate is the picture's latitude and longitude
if (abs($latitude) + abs($longitude) > 0) {
$default_center_coord = $latitude . ',' . $longitude;
$coordinates = $latitude . ',' . $longitude;
} elseif ($CONFIG['gmap_default_center'] != NULL) { //if the picture doesn't have lat/long info, use the default value
$def_coordinates = explode(',',$CONFIG['gmap_default_center']);
$default_center_coord = $def_coordinates[0] . ',' . $def_coordinates[1];
} else { //if there is no default center, use Google, Inc address
$default_center_coord = '37.42225327545478,-122.0855712890625';
}
$map_code .= <<<EOT
var map$pid = new GMap2(document.getElementById("small_map$pid"));
map$pid.setCenter(new GLatLng({$default_center_coord}), {$default_zoom_level});
map$pid.addControl(new GSmallMapControl());
/////Draggable markers
var point = new GLatLng({$default_center_coord});
var markerD$pid = new GMarker(point, {icon:icon, draggable: true});
map$pid.addOverlay(markerD$pid);
markerD$pid.enableDragging();
GEvent.addListener(markerD$pid, "drag", function(){
document.getElementById("coordinates$pid").value=markerD$pid.getPoint().toUrlValue();
});
EOT;
}
//show map if configured
if ($CONFIG['gmap_editpics_map'] == 1) {
echo <<<EOT
<tr>
<td class="tableb" valign="top" style="white-space: nowrap;">
{$lang_register_php['location']}
</td>
<td width="100%" class="tableb" valign="top" colspan="2">
<noscript>
{$lang_gmap_php['no_javascript']}
</noscript>
{$lang_gmap_php['coord_instructions']}
<div id="small_map$pid" style="width: 300px; height: 300px; color: black; margin: 5px auto;"></div>
</td>
</tr>
EOT;
}
FIND:
<input type="text" style="width: {$field_width}%" name="$name" maxlength="$max_length" value="$value" class="textinput" />
REPLACE with:
<input type="text" style="width: {$field_width}%" name="$name" maxlength="$max_length" value="$value" class="textinput" id="$name" />
</td>
</tr>
EOT;
}
//array($lang_gmap_php['coordinates'], 10, 255, 'latitude', 'longitude'),
//function form_input($text, $name, $max_length)
function form_input_gmap($text, $name, $max_length, $latitude, $longitude,$field_width=100)
{
global $CURRENT_PIC, $coordinates;
$latitude = $CURRENT_PIC[$latitude];
$longitude = $CURRENT_PIC[$longitude];
if (abs($latitude) + abs($longitude) > 0) {
$coordinates = $latitude . ',' . $longitude;
} else {
$coordinates = '';
}
$value = $coordinates;
$name .= $CURRENT_PIC['pid'];
if ($text == '') {
echo " <input type=\"hidden\" name=\"$name\" value=\"\" />\n";
return;
}
echo <<<EOT
<tr>
<td class="tableb" style="white-space: nowrap;">
$text
</td>
<td width="100%" class="tableb" valign="top">
<input type="text" style="width: {$field_width}%" name="$name" maxlength="$max_length" value="$value" class="textinput" id="$name" />
FIND:
case 4 :
form_options();
break;
AFTER it, ADD:
case 10 :
form_input_gmap($element[0], $element[1], $element[3], $element[4], $element[5]);
break;
FIND:
pagefooter();
AFTER it, ADD:
if ($CONFIG['gmap_editpics_map'] == 1) {
$gmap_code = <<<EOT
<script src="http://maps.google.com/maps?file=api&v=$version&key=$map_key" type="text/javascript">
</script>
<script type="text/javascript">
//<![CDATA[
if (GBrowserIsCompatible()) {
// "tiny" marker icon
var icon = new GIcon();
icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);
$map_code;
} else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
//]]>
</script>
EOT;
}