Click here to Skip to main content
13,288,520 members (81,036 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


23 bookmarked
Posted 20 Mar 2014

How to Make Your Own Android Weather Application Using Google Weather API

, 20 Mar 2014
Rate this:
Please Sign up or sign in to vote.
This tip shows you how to make your own Android Weather Application using XML Parsing.


If you want to make your own simple Android Weather application, you are at the right place. It is more simple if you use XML Parsing of Google Weather API. So you need to understand the XML Parsing Process, not more.


We need to use the Simple Access XML to parse the XML Document. So, you have to just know the location and the place of the result in the code of XML Document and parse it easily. For example, we want to know the weather related to Sfax Tunisia in this picture shown below:

Using the Code

At the beginning, we need to specify the City or the State for which we would like to know the weather description.

String c = city.getText().toString();
        String s = state.getText().toString();
        StringBuilder URL = new StringBuilder(BaseURL); 
        String fullUrl= URL.toString();
            URL website= new URL(fullUrl);
            //getting xmlReader to parse data
            SAXParserFactory spf= SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader() ;
            HandlingXmlStuff doingWork = new HandlingXmlStuff();
            xr.parse(new InputSource(website.openStream()));
            String information = doingWork.getInformation();
        catch(Exception e)

After that, we need to start parsing the XML Document.

public class HandlingXmlStuff extends DefaultHandler {
XMLDataCollected info = new XMLDataCollected();
public String getInformation()
    return info.dataToString();

    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        if (localName.equals("city"))
            String city=attributes.getValue("data");
        }else if (localName.equals("temp_f")){
            String t = attributes.getValue("data");
            int temp = Integer.parseInt(t);

We need to specify our data model and the functions used.

public class XMLDataCollected {
    int temp= 0;
    String city=null ; 
    public void setCity(String c)
        city= c ; 
    public void setTemp(int t )
        temp = t ;
    public String dataToString()
        return "In"+city+" the current Temp in F is "+ temp+" degrees";

Points of Interest

In this case, you have learned how to use XML Parsing in Android Application that allows you to make many features easily in your application.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hadrich Mohamed
Tunisia Tunisia
Microsoft Certified Professional, Big Data and Cloud Architect.
Mail :

You may also be interested in...


Comments and Discussions

Questionattachment download Pin
Mahesh_Bhosale28-Mar-14 21:39
memberMahesh_Bhosale28-Mar-14 21:39 
AnswerRe: attachment download Pin
Hadrich Mohamed31-Mar-14 5:11
professionalHadrich Mohamed31-Mar-14 5:11 
QuestionMore information on Google Weather API Pin
Ravi Bhavnani27-Mar-14 4:54
professionalRavi Bhavnani27-Mar-14 4:54 
AnswerRe: More information on Google Weather API Pin
Hadrich Mohamed27-Mar-14 10:52
professionalHadrich Mohamed27-Mar-14 10:52 
GeneralRe: More information on Google Weather API Pin
Ravi Bhavnani27-Mar-14 11:00
professionalRavi Bhavnani27-Mar-14 11:00 
GeneralMy vote of 1 Pin
Member 1057880827-Mar-14 0:57
memberMember 1057880827-Mar-14 0:57 
GeneralRe: My vote of 1 Pin
Hadrich Mohamed27-Mar-14 10:52
professionalHadrich Mohamed27-Mar-14 10:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 20 Mar 2014
Article Copyright 2014 by Hadrich Mohamed
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid