網頁

顯示具有 API 標籤的文章。 顯示所有文章
顯示具有 API 標籤的文章。 顯示所有文章

2013年10月28日 星期一

google app engine curl php




CURL is not supported on Google App Engine for PHP. 



Replacing CURL with urlfetch in PHP


https://developer.foursquare.com/resources/libraries

FoursquareAPI.class.php
 
 private function Request($url,$params=false,$type=HTTP_GET){

  // Populate data for the GET request
  if($type == HTTP_GET) $url = $this->MakeUrl($url,$params);

  // borrowed from Andy Langton: http://andylangton.co.uk/
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  
               // Populate data for the GET request
  $result=curl_exec($ch);
  $info=curl_getinfo($ch);
  curl_close($ch);

  return $result;
       }

 
 private function Request($url,$params=false,$type=HTTP_GET){
  
  // Populate data for the GET request
  if($type == HTTP_GET) $url = $this->MakeUrl($url,$params);
                 $result = file_get_contents($url, false, null);
  
  return $result;
        }

2013年10月23日 星期三

Foursquare API

FourSquare API integration with PHP website in 20 mins



Firstly we will create API key and secret for our App, for that we will go here:Foursquare Developer 

Now, we will use a PHP library which is readily available here: Foursquare Libraries 

RESTKIT的使用教程


Search Venues

https://api.foursquare.com/v2/venues/search
categoryIdasad13242l,btbe24353mA comma separated list of categories to limit results to. If you specify categoryId specifying a radius may improve results. If specifying a top-level category, all sub-categories will also match the query. Does not apply to match intent requests.
    $categoryId = '4bf58dd8d48988d12b951735';//Bus_line
    $params = array("ll"=>"$lat,$lng","categoryId"=>$categoryId); 

Foursquare Categories

找對應類別id
https://github.com/lomain/glowsquare/blob/master/categories.json


top-level category

Top Level Categories ID of Foursquare

  1. {
  2. "id": "4d4b7105d754a06374d81259",
  3. "name": "Food",
  4. "pluralName": "Food",
  5. "shortName": "Food",
  6. "icon": {},
  7. "categories": []
  8. },

Venue Categories

https://api.foursquare.com/v2/venues/categories


FourSquare venue search using categories


When I search using 5 categories:
// 4bf58dd8d48988d121941735 - lounge
// 4bf58dd8d48988d11f941735 - nightclub
// 4bf58dd8d48988d1e7931735 - jazz club
// 4bf58dd8d48988d1e9931735 - rock club
// 4bf58dd8d48988d1d8941735 - gay clubs

sub-categories
  • categories: [
    • {
      • id: "4bf58dd8d48988d16d941735"
      • name: "Café"
      • pluralName: "Cafés"
      • shortName: "Café"
      • icon: {
        • prefix: "https://ss1.4sqi.net/img/categories_v2/food/cafe_"
        • suffix: ".png"
        }
      • primary: true
      }
    ]

{
  "meta": {
    "code": 200
  },
  "notifications": [
    {
      "type": "notificationTray",
      "item": {
        "unreadCount": 0
      }
    }
  ],
  "response": {
    "groups": [
      {
        "type": "Recommended Places",
        "name": "recommended",
        "items": [
          {
            "reasons": {
              "count": 0,
              "items": []
            },
            "venue": {
              "id": "52b2e7af11d2a3d1701e8d0c",
              "name": "藝家書局",
              "contact": {},
              "location": {
                "lat": 25.091978,
                "lng": 121.472029,
                "distance": 46,
                "cc": "TW",
                "country": "Taiwan"
              },
   


   $url = "https://api.foursquare.com/v2/venues/explore?ll=25.0917625427,121.4716339111&radius=100&oauth_token=YOUR_KEY&v=20140327"; 

$json = file_get_contents($url);
$arr_json = json_decode($json);


$a=array();

foreach ($arr_json->response->groups[0]->items as $key => $value):
   $name = $arr_json->response->groups[0]->items[$key]->venue->name;
   $lat = $arr_json->response->groups[0]->items[$key]->venue->location->lat;
   $lng = $arr_json->response->groups[0]->items[$key]->venue->location->lng;

   $venue = array("name" => $name,"lat" =>$lat,"lng" =>$lng); 
   array_push($a,$venue );

endforeach;  


     $json_output ='{';
     $json_output .= ' "data" : ';
     $json_output .= json_encode($a) ;
     $json_output .= '}';

     echo   $json_output;

{
  "data": [
    {
      "name": "藝家書局",
      "lat": 25.091978,
      "lng": 121.472029
    },
    {
      "name": "小林紅油抄手",
      "lat": 25.091818523223,
      "lng": 121.47229998022
    }
  ]
}

Foursquare getting and displaying venues in browser

   

2013年1月29日 星期二

Google Maps API


Google Maps Javascript API 第 3 版 

PS. 新版的 Google Maps JavaScript API 已經不再需要申請 Google Maps API Key 了


教學推薦:Google Maps Overlays

            Google Maps JavaScript API v3 


基礎環境:

[MAC] MAMP架站懶人包輕鬆架設WebServer(Apache|MySQL|PHP)

實用工具:

Google Maps API 使用示範





Practice: google maps v3 + javascript + php

PHP
 $classExifReader = new ExifReader;
  $image = 'yourPhotoWithGPStag.jpg';
  $latitudeAndLongitude = $classExifReader->getGPS($image);
JS



google map move marker example

google map 控制項

change marker icon on mouseover ( google maps V3 )



總覽

地理編碼是指將地址 (例如 1600 Amphitheatre Parkway, Mountain View, CA) 轉換成地理座標 (例如緯度 37.423021 和經度 -122.083739) 的程序,而您可以使用這些座標來放置標記或設定地圖位置。