Skip to content

Instantly share code, notes, and snippets.

@sudheesh001
Created April 3, 2015 10:19
Show Gist options
  • Save sudheesh001/ee26ba3cf8bf07425d54 to your computer and use it in GitHub Desktop.
Save sudheesh001/ee26ba3cf8bf07425d54 to your computer and use it in GitHub Desktop.
Geolocation retrieval from loklak instead of hash based API

For a sample loklak query which is as follows http://loklak.net/api/search.json?q=sudheesh001 We get the following data

{
    "created_at" : "2015-04-01T06:21:44.000Z",
    "screen_name" : "sudheesh001",
    "text" : "Managed to integrate #loklak by @0rb1t3r into the GEAR Systems project for better governance #IEEE #EPICS",
    "link" : "https://twitter.com/sudheesh001/status/583152246340239361",
    "id_str" : "583152246340239361",
    "source_type" : "TWITTER",
    "provider_type" : "REMOTE",
    "provider_hash" : "7ffffffe",
    "retweet_count" : 0,
    "favourites_count" : 1,
    "images" : [ ],
    "images_count" : 0,
    "place_name" : "Warangal-Hamamkonda, Andhra Pradesh",
    "place_id" : "3fcfb985eff1817a",
    "hosts" : [ ],
    "hosts_count" : 0,
    "links" : [ ],
    "links_count" : 0,
    "mentions" : [ "0rb1t3r" ],
    "mentions_count" : 1,
    "hashtags" : [ "loklak", "IEEE", "EPICS" ],
    "hashtags_count" : 3,
    "without_l_len" : 105,
    "without_lu_len" : 96,
    "without_luh_len" : 75,
    "user" : {
      "name" : "SudheeshSinganamalla",
      "screen_name" : "sudheesh001",
      "profile_image_url_https" : "https://pbs.twimg.com/profile_images/500559201542762498/IvDEqWy1_bigger.jpeg",
      "appearance_first" : "2015-04-03T10:09:11.313Z",
      "appearance_latest" : "2015-04-03T10:09:11.313Z"
    }
  }

The place_id is a hash and can only be converted to geo-json after authenticating the app to make a request. To avoid this, One possible option could be to use the place_name which is Warangal-Hamamkonda, Andhra Pradesh in this case and make a GET request as follows http://maps.google.com/maps/api/geocode/json?address=Warangal-Hamamkonda,+Andhra+Pradesh&sensor=false resulting in

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Andhra Pradesh Dairy Development Co-operative Federation Limited Office Of The Deputy Director",
               "short_name" : "Andhra Pradesh Dairy Development Co-operative Federation Limited Office Of The Deputy Director",
               "types" : [ "point_of_interest", "establishment" ]
            },
            {
               "long_name" : "Warangal-Hyderabad Road",
               "short_name" : "Warangal-Hyderabad Rd",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Alankar",
               "short_name" : "Alankar",
               "types" : [ "sublocality_level_2", "sublocality", "political" ]
            },
            {
               "long_name" : "Brahmanawada",
               "short_name" : "Brahmanawada",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "Hanamkonda",
               "short_name" : "HNK",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Telangana",
               "short_name" : "Telangana",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "506011",
               "short_name" : "506011",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Andhra Pradesh Dairy Development Co-operative Federation Limited Office Of The Deputy Director, Warangal-Hyderabad Road, Alankar, Brahmanawada, Hanamkonda, Telangana 506011, India",
         "geometry" : {
            "location" : {
               "lat" : 18.0017782,
               "lng" : 79.58019929999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 18.0031271802915,
                  "lng" : 79.5815482802915
               },
               "southwest" : {
                  "lat" : 18.0004292197085,
                  "lng" : 79.57885031970848
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ChIJUW0pC3VFMzoRl5rpS5jFkgU",
         "types" : [ "point_of_interest", "establishment" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Government Of Andhra Pradesh Regional Library",
               "short_name" : "Government Of Andhra Pradesh Regional Library",
               "types" : [ "point_of_interest", "establishment" ]
            },
            {
               "long_name" : "Sardar Vallabhai Patel Road",
               "short_name" : "Sardar Vallabhai Patel Rd",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Rangampet",
               "short_name" : "Rangampet",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Telangana",
               "short_name" : "Telangana",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "506007",
               "short_name" : "506007",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Government Of Andhra Pradesh Regional Library, Sardar Vallabhai Patel Road, Rangampet, Warangal, Telangana 506007, India",
         "geometry" : {
            "location" : {
               "lat" : 17.9966202,
               "lng" : 79.58901829999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 17.9979691802915,
                  "lng" : 79.59036728029149
               },
               "southwest" : {
                  "lat" : 17.9952712197085,
                  "lng" : 79.58766931970848
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ChIJC1dqkw5FMzoR3TGA1WOw540",
         "types" : [ "library", "point_of_interest", "establishment" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Urdu Academy Library Andhra Pradesh",
               "short_name" : "Urdu Academy Library Andhra Pradesh",
               "types" : [ "point_of_interest", "establishment" ]
            },
            {
               "long_name" : "H.No. 7-7-47",
               "short_name" : "H.No. 7-7-47",
               "types" : [ "subpremise" ]
            },
            {
               "long_name" : "Opp. Mohammed Khan Jewellers, Ujli Base, Warangal District Centre",
               "short_name" : "Opp. Mohammed Khan Jewellers, Ujli Base, Warangal District Centre",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brahmanawada",
               "short_name" : "Brahmanawada",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "Hanamkonda",
               "short_name" : "HNK",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Telangana",
               "short_name" : "Telangana",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "506001",
               "short_name" : "506001",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "H.No. 7-7-47, Urdu Academy Library Andhra Pradesh, Opp. Mohammed Khan Jewellers, Ujli Base, Warangal District Centre, Brahmanawada, Hanamkonda, Telangana 506001, India",
         "geometry" : {
            "location" : {
               "lat" : 18.0034669,
               "lng" : 79.5761569
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 18.0048158802915,
                  "lng" : 79.5775058802915
               },
               "southwest" : {
                  "lat" : 18.0021179197085,
                  "lng" : 79.57480791970849
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ChIJ4TNY8Z1FMzoRNtaDKHQQ07A",
         "types" : [ "library", "point_of_interest", "establishment" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Andhra Pradesh Road Transport Authority Office",
               "short_name" : "Andhra Pradesh Road Transport Authority Office",
               "types" : [ "point_of_interest", "establishment" ]
            },
            {
               "long_name" : "Sri Sai Nagar",
               "short_name" : "Sri Sai Nagar",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Telangana",
               "short_name" : "Telangana",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "506002",
               "short_name" : "506002",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Andhra Pradesh Road Transport Authority Office, Sri Sai Nagar, Warangal, Telangana 506002, India",
         "geometry" : {
            "location" : {
               "lat" : 17.9395155,
               "lng" : 79.59935399999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 17.9408644802915,
                  "lng" : 79.60070298029149
               },
               "southwest" : {
                  "lat" : 17.9381665197085,
                  "lng" : 79.59800501970848
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ChIJt4f6A9xaMzoRrrQYMdXkn5g",
         "types" : [ "point_of_interest", "establishment" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Office of The Andhra Pradesh Education And Welfare Infrastructure Development Corporation",
               "short_name" : "Office of The Andhra Pradesh Education And Welfare Infrastructure Development Corporation",
               "types" : [ "point_of_interest", "establishment" ]
            },
            {
               "long_name" : "Warangal-Hyderabad Road",
               "short_name" : "Warangal-Hyderabad Rd",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Revenue Colony",
               "short_name" : "Revenue Colony",
               "types" : [ "sublocality_level_2", "sublocality", "political" ]
            },
            {
               "long_name" : "Subedari",
               "short_name" : "Subedari",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "Hanamkonda",
               "short_name" : "HNK",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Telangana",
               "short_name" : "Telangana",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "506001",
               "short_name" : "506001",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Office of The Andhra Pradesh Education And Welfare Infrastructure Development Corporation, Warangal-Hyderabad Road, Revenue Colony, Subedari, Hanamkonda, Telangana 506001, India",
         "geometry" : {
            "location" : {
               "lat" : 17.9932458,
               "lng" : 79.54165189999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 17.9945947802915,
                  "lng" : 79.5430008802915
               },
               "southwest" : {
                  "lat" : 17.9918968197085,
                  "lng" : 79.54030291970849
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ChIJ6zOUEZlPMzoRBtAYa7AEMWw",
         "types" : [ "point_of_interest", "establishment" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Warangal Public School",
               "short_name" : "Warangal Public School",
               "types" : [ "point_of_interest", "establishment" ]
            },
            {
               "long_name" : "Hunter Road",
               "short_name" : "Hunter Rd",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Near Adalath Circle",
               "short_name" : "Near Adalath Circle",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Advocate Colony",
               "short_name" : "Advocate Colony",
               "types" : [ "sublocality_level_2", "sublocality", "political" ]
            },
            {
               "long_name" : "Nakkalagutta",
               "short_name" : "Nakkalagutta",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "Hanamkonda",
               "short_name" : "HNK",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Warangal",
               "short_name" : "Warangal",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Andhra Pradesh",
               "short_name" : "Andhra Pradesh",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "506001",
               "short_name" : "506001",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Warangal Public School, Hunter Road, Near Adalath Circle, Advocate Colony, Nakkalagutta, Hanamkonda, Andhra Pradesh 506001, India",
         "geometry" : {
            "location" : {
               "lat" : 17.9950937,
               "lng" : 79.55382349999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 17.9964426802915,
                  "lng" : 79.5551724802915
               },
               "southwest" : {
                  "lat" : 17.9937447197085,
                  "lng" : 79.55247451970848
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ChIJp1HTD4RPMzoR6azzkdMLekM",
         "types" : [ "point_of_interest", "establishment" ]
      }
   ],
   "status" : "OK"
}

This looks promising as an integration to loklak

@Orbiter
Copy link

Orbiter commented Apr 3, 2015

I tested that google service already i.e. with 'London' and got also results about Basel, Switzerland. The method may be feasible in some cases but still stays extremely fuzzy. Another problem is that we are then also dependend on a google service. I consider this solution but would prefer to have a 'hack' on the place_id: i hope that in some way there is the actual location coded inside the hex numbers. I already tried to find a pattern but did not succeed yet. Can you have a look at that 'hash', it maybe is just a nice geoloc-encoding.

@Orbiter
Copy link

Orbiter commented Apr 3, 2015

to become independent from Google and to improve performance of location search it could be possible to integrate a loklak-internal location database, based on a dbpedia dump from http://data.dws.informatik.uni-mannheim.de/dbpedia/2014/en/geo_coordinates_en.ttl.bz2

@Orbiter
Copy link

Orbiter commented Jun 25, 2015

this feature has been implemented loklak/loklak_server@4501c7b without any outside service. The location database is integrated in loklak and taken from the GeoNames file http://download.geonames.org/export/dump/cities1000.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment