Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Get ISO country code for the given latitude longitude using GeoNames Web Service using HttpURLConnection

| 0 comments |
The GeoNames geographical database covers all countries and contains over eight million placenames that are available for download free of charge. We can get the iso country code for any given latitude/longitude, using GeoNames webservices; api.geonames.org/countryCode?



CountryCode / reverse geocoding

The iso country code of any given point.
Webservice Type : REST 
Url : api.geonames.org/countryCode?
Parameters : lat,lng, type, lang, radius (buffer in km for closest country in coastal areas, a positive buffer expands the positiv area whereas a negative buffer reduces it);
Result : returns the iso country code for the given latitude/longitude
With the parameter type=xml this service returns an xml document with iso country code and country name. The optional parameter lang can be used to specify the language the country name should be in. JSON output is produced with type=JSON
Example http://api.geonames.org/countryCode?lat=47.03&lng=10.2&username=demo 

Important:

  • Do not use the demo account for your app or your tests. It is only meant for the sample links on the documentation pages. Create your own account instead.
  • The parameter username needs to be passed with each request. The username for your application can be registered here. You will then receive an email with a confirmation link and after you have confirmed the email you can enable your account for the webservice on your account page
  • Dont forget to url encode string parameters containing special characters or spaces. (Faq entry on url encoding)
  • ...
read details: http://www.geonames.org/export/web-services.html


Its a example to get the ISO country code of user entered latitude/longitude.


MainActivity.java
package com.blogspot.android_er.androidgeonames;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

EditText latText;
EditText lonText;
Button btnFind;
TextView textResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
latText = (EditText)findViewById(R.id.latText);
lonText = (EditText)findViewById(R.id.lonText);
btnFind = (Button)findViewById(R.id.find);
textResult = (TextView)findViewById(R.id.result);

btnFind.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String strLat = latText.getText().toString();
String strLon = lonText.getText().toString();

new GeoNamesTask(textResult).execute(strLat, strLon);
}
});
}

private class GeoNamesTask extends AsyncTask<String, Void, String> {
TextView tResult;

public GeoNamesTask(TextView vResult){
tResult = vResult;
tResult.setText("");
}

@Override
protected String doInBackground(String... params) {

/*
Do not use the demo account for your app or your tests.
It is only meant for the sample links on the documentation pages.
Create your own account instead.
*/
String queryString =
"http://api.geonames.org/countryCode?lat=" + params[0]
+ "&lng=" + params[1] + "&username=demo";

String s = "";
try {
s = sendQuery(queryString);
} catch (IOException e) {
e.printStackTrace();
s = e.getMessage();
}
return s;
}

@Override
protected void onPostExecute(String s) {
tResult.setText(s);
}


private String sendQuery(String query) throws IOException {
String result = "";

URL searchURL = new URL(query);

HttpURLConnection httpURLConnection = (HttpURLConnection)searchURL.openConnection();
if(httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK){
InputStreamReader inputStreamReader = new InputStreamReader(httpURLConnection.getInputStream());
BufferedReader bufferedReader = new BufferedReader(
inputStreamReader,
8192);

String line = null;
while((line = bufferedReader.readLine()) != null){
result += line;
}

bufferedReader.close();
}

return result;
}
}
}


layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout


android_layout_width="match_parent"
android_layout_height="match_parent"
android_padding="16dp"
android_orientation="vertical"
tools_context=".MainActivity">

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center_horizontal"
android_autoLink="web"
android_text="http://android-er.blogspot.com/"
android_textStyle="bold" />

<EditText
android_id="@+id/latText"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_inputType="numberSigned|numberDecimal"
android_hint="Latitude"
android_text="47.03"/>

<EditText
android_id="@+id/lonText"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_inputType="numberSigned|numberDecimal"
android_hint="Longitude"
android_text="10.2"/>

<Button
android_id="@+id/find"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_text="find"/>

<TextView
android_id="@+id/result"
android_layout_width="match_parent"
android_layout_height="wrap_content" />
</LinearLayout>


Permission of "android.permission.INTERNET" is needed in AndroidManifest.xml
 <uses-permission android_name="android.permission.INTERNET"/>

Next:
GeoNames also provide Java Client for GeoNames Webservices to help developers to easily access the geonames web services with java. Next post "Get ISO country code for the given latitude/longitude, using GeoNames Java Client" show how to use it in Android Studio project.

Related:
- Find addresses of given latitude and longitude using android.location.Geocoder

Read More..

Introducing the Senior Web Developer Nanodegree Program with Udacity

| 0 comments |

Posted by Sarah Clark, Program Manager, Google Developer Training

What do you need to stand out from the crowd of web developers, and ultimately, land that perfect job?

We asked ourselves that same question and decided to help by introducing the Senior Web Developer Nanodegree. Built in collaboration with Udacity, this online program is designed to teach you the tools, frameworks, and techniques needed to write robust code for progressive web applications that are secure and easy to use. Spending about 10 hours a week, most students can earn this Nanodegree credential in 9-12 months at a cost of $200 per month with 50% returned upon completion.

Along the way, you will also learn how to integrate new technologies, such as Service Worker and Web Components, and work extensively with Gulp and other tools. You’ll hear from Google experts, such as Ido Green, Jake Archibald (co-author of the Service Worker spec), Luke Wroblewski (author and strategist), Paul Bakaus (Studio 5 CTO, Zynga) and Alice Boxhall (author of the Chrome accessibility developer tools).

How can you get started? There are two different ways to participate. One option is the paid Nanodegree program, which includes code-level project reviews and feedback, coaching, support from a cohort of peers, building a portfolio of work, and career support services. The second option is entirely free and includes the same instructional courses, quizzes and projects individually, which you can take at your own pace.

For more details, and to be notified when enrollment opens, check out udacity.com/googlewebdev.

Read More..

Connecting to a web service over a Secure Sockets Layer SSL protocol

| 0 comments |
Android default HttpClinet does not support SSL connections, so if you have a secured web service, you need to connect to it via javax.net.ssl.HttpsURLConnection.
if you want to call a SSL SOAP web service:
String CallWebService(String url,
String soapAction,
String envelope) throws IOException {
URL address=new URL(url);
URLConnection connection=address.openConnection();
HttpsURLConnection post=(HttpsURLConnection)connection;
post.setDoInput(true);
post.setDoOutput(true);
post.setRequestMethod("POST");
post.setRequestProperty("SOAPAction", soapAction);
post.setRequestProperty( "Content-type", "text/xml; charset=utf-8" );
post.setRequestProperty( "Content-Length", String.valueOf(envelope.length()));
post.setReadTimeout(4000);

OutputStream outStream=post.getOutputStream();
Writer out=new OutputStreamWriter(outStream);
out.write(envelope);
out.flush();
out.close();


InputStream inStream = post.getInputStream();
BufferedInputStream in = new BufferedInputStream(inStream,4);
StringBuffer buffer=new StringBuffer();
// read 4 bytes a time
byte[] buffArray=new byte[4];
int c=0;
while((c=in.read(buffArray))!=-1){
for(int i=0;i<c;i++)
buffer.append((char)buffArray[i]);
}

return buffer.toString();
}
Read More..

Web 2 0 for the software services industry

| 0 comments |
Here are some of my thoughts on what Web 2.0 would mean to the software services industry.

The five main principles that qualify for calling and application / site Web 2.0 is:
1. Web as a Platform and Software as a service
2. Architecture of participation for harnessing collective intelligence
3. Own or create hard-to-recreate data sources
4. Software through multiple channels and devices
5. Rich User interface or Rich Internet Applicaitons

While the principle 2 seems to be attracting the most attention in Web 2.0, for the services industry, principle 1 holds the key.

Let me elaborate what I mean. In terms of implementation, principle 2 stands for creating and enhancing the network of people visiting your applicaitons and using them or adding value to them through blogs, wikis, social networks, susbscription of feeds, provide permalinks and trackbacks, allowing tagging or folsonomy as some call it. Now, providing or building these features is a breeze. Most of them can be just configured by using many available off-the-shelf, open source software.

Also, practically speaking, if an organization does not have a core business around which to implement web 2.0, just providing the above is not going to be of any value add to itself.

The crux continues to remain that any organization must have a core business model that needs to adapt itself to Web 2.0. By this I mean, they must be providing some service in the real world and that should preferrably have already made its presence on the web through the Web 1.0 way. Even if not, it needs to be morphed to be provided as an online service, in the first go.

This is nothing but extending the web service model to the real "web". While the former was more often than not, within the walls of an enterprise or extended mainly to business partners, the latter would be real services maintained for the public use on the web by anyone who subscribes and pays for it. This would mainly help the smaller business of both types: the providers of such services as well as the consumers of such services.

There are enough successful models over the last couple of years like the salesforce.com which are thriving on this business model, a model of revenue generation that did not exist inherently in web 1.0. This may be one of the main causes for a potential success of Web 2.0, as I see it.
Read More..

Componentize the web with Polycasts!

| 0 comments |
Today at Google, we’re excited to announce the launch of Polycasts, a new video series to get developers up and running with Polymer and Web Components.

Web Components usher in a new era of web development, allowing developers to create encapsulated, interoperable elements that extend HTML itself. Built atop these new standards, Polymer makes it easier and faster to build Web Components, while also adding polyfill support so they work across all modern browsers.

Because Polymer and Web Components are such big changes for the platform, there’s a lot to learn, and it can be easy to get lost in the complexity. For that reason, we created Polycasts.

Polycasts are designed to be bite sized, and to teach one concept at a time. Along the way we plan to highlight best practices for not only working with Polymer, but also using the DevTools to make sure your code is performant.

We’ll be releasing new videos often over the coming weeks, initially focusing on core elements and layout. These episodes will also be embedded throughout the Polymer site, helping to augment the existing documentation. Because there’s so much to cover in the Polymer universe, we want to hear from you! What would you like to see? Feel free to shoot a tweet to @rob_dodson, if you have an idea for a show, and be sure to subscribe to our YouTube channel so you’re notified when new episodes are released.

Posted by Rob Dodson, Developer Advocate
Read More..

Get your students on the same web page instantly

| 0 comments |
Posted by Catherine Davis, former 4th grade teacher and Director of Academic Technology at Pilgrim School

(Cross-posted on the Google for Education Blog.)




Editors note: Today we’re launching a new Chrome extension, Share to Classroom, which solves a big pain point for teachers: getting all students to the same website during class. The Share to Classroom extension works on any laptop, including Chromebooks, Macs and PCs. Catherine Davis, former 4th grade teacher and Director of Academic Technology at Pilgrim School, piloted the Classroom extension with Mrs. Shorkey’s 3rd grade class, and here she describes her experience using this new extension and the impact on her students.







Sharing a website with my students is a great way to get them engaged. When we studied South America, I shared a video of Tierra del Fuego, and my students were able to view the coast, hear the wind and see the waves soar. But getting a class full of 4th graders on the same web page is a huge challenge. I typically write the URL on the board, then walk around to help each student who misses a capital or underscore or backslash. My students get frustrated, I get frustrated, and before I know it 10 minutes of precious teaching time is lost.

So I was thrilled to pilot the Share to Classroom extension. With the extension I can open a website and “push” it to my Google Classroom students, so the page opens immediately on all their devices. Our 3rd graders gasped when we tried it – the webpage instantaneously popped up on all of their screens.
The new extension lets me engage my students and help them drive their own learning on 1:1 devices at our school. When our 3rd graders were studying Native American culture, I pushed a website to the class so they could research traditional clothing and food. The students aren’t locked to the page I send, and one student navigated from there to an even better site. With the Classroom extension, the student was able to push the new site to me, and I reviewed and pushed to the entire class. She had a boost of confidence when her discovery drove class discussion.
Using the extension also lets me think on my feet. When discussing pioneers, a brave student raised his hand and asked “What’s a stage coach?” I realized my students hadn’t been exposed to the term. I immediately pulled up a definition and video and pushed it to the class. I also saved the webpage as a draft to post to my other Classroom students later. I could have projected on a screen, but the intimacy of having the webpage on each device allows students to explore on their own, hear clearly and watch repeatedly. It also levels the playing field for ELL and students of different backgrounds so everyone starts literally on the same page.

As teachers, we never feel we have enough time to do everything we want with our students. The new Share to Classroom extension gives us back those few minutes it takes to get students to the same place and makes learning about investigating, not about navigating.

*Note: Google Apps admins can install the extension for their entire domain so that it’s easiest for teachers and students to get started. Teachers and students both need the extension in order to push web pages to each other.
Read More..