Google Maps API(Flash 版)的“Hello World”
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<maps:Map xmlns:maps="com.google.maps.*" id="map" mapevent_mapready="onMapReady(event)" width="100%" height="100%" key="your_api_key"/>
<mx:Script>
<![CDATA[
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
private function onMapReady(event:Event):void {
this.map.setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
}
]]>
</mx:Script>
</mx:Application>
演示地址:http://gmaps-samples-flash.googlecode.com/svn/trunk/examples/HelloWorld.html
想更快了解更多Google Maps API(Flash 版)
http://code.google.com/intl/zh-CN/apis/maps/documentation/flash/intro.html
2013年1月2日 星期三
2013年1月1日 星期二
Google URL Shortener PHP Class
Google has had a URL shortening domain for quite a while now but it wasn't until recently that Google exposed the URL shortening API to the public. I took a few minutes to review their API and created a very basic GoogleUrlApi class that will shorten long URLs and expand shortened URLs.
The PHP
The class itself is quite compact and the code should be easy to read:
The constructor requires your Google API key. A second argument may be provided to the URL of the Google API. As the API is currently in version 1, changing this URL would be more harmful than useful. The class features two main methods: shorten and expand. Each method takes the long or short URL, contacts Google, and returns its counterpart. If no counterpart is found, or the Google URL Shortener API is down, a result of false is returned, so please be sure to use your own error handling. Now let's create an instance of GoogleUrlApi to shorten and then expand a URL:
// Declare the class
class GoogleUrlApi {
// Constructor
function GoogleURLAPI($key,$apiURL = 'https://www.googleapis.com/urlshortener/v1/url') {
// Keep the API Url
$this->apiURL = $apiURL.'?key='.$key;
}
// Shorten a URL
function shorten($url) {
// Send information along
$response = $this->send($url);
// Return the result
return isset($response['id']) ? $response['id'] : false;
}
// Expand a URL
function expand($url) {
// Send information along
$response = $this->send($url,false);
// Return the result
return isset($response['longUrl']) ? $response['longUrl'] : false;
}
// Send information to Google
function send($url,$shorten = true) {
// Create cURL
$ch = curl_init();
// If we're shortening a URL...
if($shorten) {
curl_setopt($ch,CURLOPT_URL,$this->apiURL);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode(array("longUrl"=>$url)));
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-Type: application/json"));
}
else {
curl_setopt($ch,CURLOPT_URL,$this->apiURL.'&shortUrl='.$url);
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// Execute the post
$result = curl_exec($ch);
// Close the connection
curl_close($ch);
// Return the result
return json_decode($result,true);
}
}
The constructor requires your Google API key. A second argument may be provided to the URL of the Google API. As the API is currently in version 1, changing this URL would be more harmful than useful. The class features two main methods: shorten and expand. Each method takes the long or short URL, contacts Google, and returns its counterpart. If no counterpart is found, or the Google URL Shortener API is down, a result of false is returned, so please be sure to use your own error handling. Now let's create an instance of GoogleUrlApi to shorten and then expand a URL:
// Create instance with key
$key = 'xhjkhzkhfuh38934hfsdajkjaf';
$googer = new GoogleURLAPI($key);
// Test: Shorten a URL
$shortDWName = $googer->shorten("http://davidwalsh.name");
echo $shortDWName; // returns http://goo.gl/i002
// Test: Expand a URL
$longDWName = $googer->expand($shortDWName);
echo $longDWName; // returns http://davidwalsh.name
Google Cloud Messaging for Android
Cloud-to-device-messaging (C2DM) is coming out of beta and
getting a new name: Google Cloud Messaging for Android. GCM for Android
incorporates the lessons we learned in the C2DM beta, many of which take
the form of new features. This session will cover the new service
end-to-end and in detail.
訂閱:
文章 (Atom)