All pastes #268186 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-12-05 12:42 UTC
rendered paste body
<?php

require_once 'XML/RPC.php';

function get_coords() {
	$host    = 'www.php-gtk.eu';
	$port    = 80;
	$backend = '/xmlrpc.php';
	$params = array (
	new XML_RPC_Value( $start_nicks='',  'string'),
	new XML_RPC_Value( $max_nicks=50,    'int')
	);
	$msg = new XML_RPC_Message('gtkphpnet.geo_nick', $params);

	$cli = new XML_RPC_Client($backend, $host);

	$resp = $cli->send($msg);
	if (!$resp) {
		echo 'Communication error: ' . $cli->errstr;
		exit;
	}

	if (!$resp->faultCode()) {
		$val = $resp->value();
		$data = XML_RPC_decode($val);
		global $image;
		$pixbuf = $image->get_pixbuf();
		foreach ($data as $lat_lon) {
			$lat = $lat_lon[0];
			$lon = $lat_lon[1];
			$x_y = getlocationcoords($lat,$lon);
			$pixbuf->put_pixel($x_y['x'],$x_y['y'],1);
		}
		$image->set_from_pixbuf($pixbuf);
		// put_pixel(int x, int y, int pixel or red [, int green [, int blue [, int alpha]]]);
	} else {
		echo 'Fault Code: ' . $resp->faultCode() . "\n";
		echo 'Fault Reason: ' . $resp->faultString() . "\n";
	}
}

function getlocationcoords($lat, $lon, $width = 310, $height = 155) {
	$x = (($lon + 180) * ($width / 360));
	$y = ((($lat * -1) + 90) * ($height / 180));
	return array("x"=>round($x),"y"=>round($y));
}

$vbox = new GtkVBox();
$image = new GtkImage();
$button = new GtkButton();
$button->set_label('get coords');
$button->connect_simple('clicked', 'get_coords');
$vbox->pack_start($image);
$vbox->pack_end($button);
$wnd = new GtkWindow();
$wnd->add($vbox);
$wnd->connect_simple('destroy',array('Gtk','main_quit'));

$image->set_from_file('earth_310.jpg');

$wnd->show_all();

Gtk::main();

?>