Bookmark and Share
Showing posts with label GEO API. Show all posts
Showing posts with label GEO API. Show all posts

Wednesday, January 09, 2013

Google locale api: find news based on your IP location



Some experiments with google apis, this page loads the google search control and finds events near your current location. If the page doesn't work please open this post alone.

Your location is....
Loading...

Here is the code used:
<script src="https://www.google.com/jsapi?key=ABQIAAAAQLd5290Kjbk-VPuCDYAfnBRYfKp0eaDcp4nidsc0rBpfwGQjWBRfZ98_xA1kmbh3biVQCxgc_Nv5_Q" 
type="text/javascript">
</script><br />
<script language="Javascript" type="text/javascript">
    //<![CDATA[
 
var position = "";
var latitude = 0;
var longitude = 0;
var city = "";
 
function loadJson(data)
{
if (data!=null)
{
 
$('#geolocation').append(data["geoplugin_city"]); 
$('#geolocation').append("-");
$('#geolocation').append(data["geoplugin_countryName"]); 
 
position = data["geoplugin_city"] + "," + data["geoplugin_countryName"];
city = data["geoplugin_city"];
OnLoad();
}
}
 
function jqLoaded() 
{
var url = "http://www.geoplugin.net/json.gp?jsoncallback=?";
var urlNearBy = "http://www.geoplugin.net/extras/nearby.gp?radius=50&limit=20&format=json&jsoncallback=?";
$.getJSON(url ,  loadJson       ); 
}
 
google.load("jquery", "1.4.3");  
google.setOnLoadCallback(jqLoaded);
 
    google.load("search", "1");
 
 
    function OnLoad() {
      // Create a search control
      var searchControl = new google.search.SearchControl();
 
      // Add in a full set of searchers
      var localSearch = new google.search.LocalSearch();
      searchControl.addSearcher(localSearch);
      searchControl.addSearcher(new google.search.NewsSearch());
      searchControl.addSearcher(new google.search.BlogSearch());
 
      // Set the Local Search center point
      localSearch.setCenterPoint(position);
 
      // Tell the searcher to draw itself and tell it where to attach
      searchControl.draw(document.getElementById("searchcontrol"));
 
      // Execute an inital search
      searchControl.execute(city);
    }
    //google.setOnLoadCallback(OnLoad);
 
    //]]>
    
</script><br />
Some experiments with google apis, this page loads the google search control 
and finds events near your current location. View the source code of the page 
if you want to see the javascript code used.<br />
<br />
<br />
<div id="geolocation">
Your location is....</div>
<div id="searchcontrol">
Loading...</div>
<br />

Wednesday, June 22, 2011

How to geolocalize “on the fly” multiple text addresses

If you have a list of addresses and you need to geolocalize them you can use this service:

http://www.gpsvisualizer.com/geocoder/

Simply copy in the first text input your list, one address per line, and then click on geocoding:

image

Every address will be associated to his latitude and longidute using yahoo geo api.

image

Hope it helps!

Nations of the world in javascript array

If you need a list on continents and nations in javascript format here is the code:

var continents =
[
["Africa","Algeria,Angola,Benin,Botswana,Burkina,Burundi,Cameroon,Cape Verde,Central African Republic,Chad,Comoros,Congo,Congo, Democratic Republic of,Djibouti,Egypt,Equatorial Guinea,Eritrea,Ethiopia,Gabon,Gambia,Ghana,Guinea,Guinea-Bissau,Ivory Coast,Kenya,Lesotho,Liberia,Libya,Madagascar,Malawi,Mali,Mauritania,Mauritius,Morocco,Mozambique,Namibia,Niger,Nigeria,Rwanda,Sao Tome and Principe,Senegal,Seychelles,Sierra Leone,Somalia,South Africa,Sudan,Swaziland,Tanzania,Togo,Tunisia,Uganda,Zambia,Zimbabwe"],
["Asia","Bangladesh,Bhutan,Brunei,Burma (Myanmar),Cambodia,China,East Timor,India,Indonesia,Japan,Kazakstan,Korea,North,Korea, South,Laos,Malaysia,Maldives,Mongolia,Nepal,Philippines,Russian Federation,Singapore,Sri Lanka,Thailand,Vietnam"],
["Europe","Albania,Andorra,Armenia,Austria,Azerbaijan,Belarus,Belgium,Bosnia and Herzegovina,Bulgaria,Croatia,Cyprus,Czech Republic,Denmark,Estonia,Finland,France,Georgia,Germany,Greece,Hungary,Iceland,Ireland,Italy,Latvia,Liechtenstein,Lithuania,Luxembourg,Macedonia,Malta,Moldova,Monaco,Montenegro,Netherlands,Norway,Poland,Portugal,Romania,San Marino,Serbia,Slovakia,Slovenia,Spain,Sweden,Switzerland,Ukraine,United Kingdom,Vatican City"],
["North America","Antigua and Barbuda,Bahamas,Barbados,Belize,Canada,Costa Rica,Cuba,Dominica,Dominican Republic,El Salvador,Grenada,Guatemala,Haiti,Honduras,Jamaica,Mexico,Nicaragua,Panama,Saint Kitts and Nevis,Saint Lucia,Saint Vincent and the Grenadines,Trinidad and Tobago,United States"],
["Oceania","Australia,Fiji,Kiribati,Marshall Islands,Micronesia,Nauru,New Zealand,Palau,Papua New Guinea,Samoa,Solomon Islands,Tonga,Tuvalu,Vanuatu"],
["South America","Argentina,Bolivia,Brazil,Chile,Colombia,Ecuador,Guyana,Paraguay,Peru,Suriname,Uruguay,Venezuela"],
["Middle East","Afghanistan,Bahrain,Iran,Iraq,Israel,Jordan,Kuwait,Kyrgyzstan,Lebanon,Oman,Pakistan,Qatar,Saudi Arabia,Syria,Tajikistan,Turkey,Turkmenistan,United Arab Emirates,Uzbekistan,Yemen"]
];

 

This is useful if you need to find using google geolocation the continent of a nation.

Here is the firebug console:

image

hope it helps!

How to generate KML file from excel data (or csv!)

The marketing department gives you an excel file and says : “it would be nice to have this data available on gGogle Earth (and also on Google Maps! ”…. can you do this today?

Instead of running out of the room with your hands in your hair simply download the excel file located at http://processtrends.com/Files/MapExcelData.zip 

Follow the instructions and in 10 minutes you will have the data geolocated and a beautiful kml file.

This is the excel file:

image

The generated KML file:

image

And the kml file in viewed in Google Earth:

image

Many thanks to http://processtrends.com and to simon_a !

Monday, November 08, 2010

How to call Outside.in location service using c#

If you are evaluating the Outside.in localized news service you may find useful this little command line program, it generates the right MD5 security code and it calls the "Location by name" service:

Here a basic test program written in c#, I think is a good start, it queries for locations:

///////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Security.Cryptography;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter location,for example new york:");
string action = Console.ReadLine();
while (action != "")
{
string search;
search = action;

string mykey = "xxx";
string shared_secret = "xxx";
int unixTime = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
string sUrl = "http://hyperlocal-api.outside.in/v1.1/locations/named/" + search + "?dev_key=" + mykey + "&amp;sig=" + MD5_ComputeHexaHash(mykey + shared_secret + unixTime.ToString());

WebRequest wrGETURL;
wrGETURL = WebRequest.Create(sUrl);

Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();

StreamReader objReader = new StreamReader(objStream);

string sLine = "";
int i = 0;

while (sLine != null)
{
i++;
sLine = objReader.ReadLine();
if (sLine != null)
Console.WriteLine("{0}:{1}", i, sLine);
}
action = Console.ReadLine();
}
}

public static string MD5_ComputeHexaHash(string text)
{
// Gets the MD5 hash for text
MD5 md5 = new MD5CryptoServiceProvider();
byte[] data = Encoding.Default.GetBytes(text);
byte[] hash = md5.ComputeHash(data);
// Transforms as hexa
string hexaHash = "";
foreach (byte b in hash)
{
hexaHash += String.Format("{0:x2}", b);
}
// Returns MD5 hexa hash
return hexaHash;
}
}
}