tag:blogger.com,1999:blog-27807297190740034662024-03-13T17:00:18.726-07:00myblogwang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-2780729719074003466.post-86117814651434986242015-07-16T13:00:00.002-07:002015-07-16T13:00:57.033-07:00address to coordinates transformation through openstreetmap http://nominatim.openstreetmap.org/search/gb/birmingham/pilkington%20avenue/135?format=xml&polygon=1&addressdetails=1
Search through the above url and the response is in xml format.
I have written a java app to convert address to coordinates
here is my code:
package javaconnection;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class JavaConnection
{
public static void main(String[] args) throws MalformedURLException, IOException, SAXException, ParserConfigurationException, Exception
{
String roadnumber = "135";
String AvenuneName = "pilkington";
String avenue = "avenue";
String Country = "birmingham";
String BaseURL = "http://nominatim.openstreetmap.org/search/";
String uri =
BaseURL + roadnumber + "%20" + AvenuneName + "%20"
+ avenue + "," + "%20" + Country
+ "?format=xml&point=1&addressdetails=1";
URL url = new URL(uri);
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
InputStream xml = connection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(xml);
prettyPrint(doc);
}
public static final void prettyPrint(Document xml) throws Exception
{
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
tf.setOutputProperty(OutputKeys.INDENT, "yes");
Writer out = new StringWriter();
tf.transform(new DOMSource(xml), new StreamResult(out));
for (String coordinates : out.toString().split(" "))
{
if(coordinates.contains("lon="))
System.out.println(coordinates);
if(coordinates.contains("lat="))
System.out.println(coordinates);
}
// System.out.println(out.toString());
}
}wang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.com0tag:blogger.com,1999:blog-2780729719074003466.post-86872079193343346702010-03-11T17:59:00.000-08:002010-03-11T18:13:08.600-08:00a question about stackin class we learned how S.pop() delete data in stack. My question is that whether we should delete data in reverse order?
<br />
<br /> S.push(Student("Fardad", "oop344", 56));
<br />
<br /> S.push(Student("John", "int322", 100));
<br /> S.push(Student("Jack", "int422", 90));
<br /> S.pop();
<br /> S.pop();
<br /> while(!S.IsEmpty()){
<br /> cout<<S.pop()<<endl;
<br /> }
<br />Student StdStack::pop(){
<br /> Student ret = top->data;
<br /> Node* ToDel = top;
<br /> top = top->next;
<br /> delete ToDel;
<br /> return ret;
<br />}
<br />the output is Fardad, oop344: 56
<br />
<br />i read some material in btp300
<br />Element pop() {
<br /> Element data;
<br /> if (head) {
<br /> Node* p = head;
<br /> data = head->data;
<br /> head = head->next;
<br /> delete p;
<br /> }
<br /> return data;
<br /> }
<br />
<br />Stack s;
<br />
<br /> // Push Data Onto Stack
<br /> s.push(3);
<br /> s.push(5);
<br /> s.push(9);
<br /> s.push(8);
<br />
<br /> // Remove first Node
<br /> s.pop();
<br />
<br /> // Pop Data Off Stack
<br /> while (!s.empty())
<br /> cout << s.pop().out() << ' ';
<br /> cout << endl;
<br />
<br />the output is 9 5 3
<br />
<br />could any one explain the difference between this two example why the pop() are different?
<br />wang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.com2tag:blogger.com,1999:blog-2780729719074003466.post-45506352719563944362010-02-22T19:53:00.000-08:002010-02-22T20:03:34.288-08:00need help for tab_keyi find that when you insert '\t' in a string. it inserts 4 ' ' forward. But we write the bio library we can not control cursor to pass '\t' character.So can anyone teach me how to move cursor to pass '\t'?wang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.com1tag:blogger.com,1999:blog-2780729719074003466.post-28601178523604915022010-02-14T20:16:00.000-08:002010-02-14T20:21:26.833-08:00reiview for pointer and pointer to functiondifferent type of pointer.<br /> a) int a; // An integer<br /> b) int *a; // A pointer to an integer<br /> c) int **a; // A pointer to a pointer to an integer<br /> d) int a[10]; // An array of 10 integers<br /> e) int *a[10]; // An array of 10 pointers to integers<br /> f) int (*a)[10]; // A pointer to an array of 10 integers<br /> g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer<br /> h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integerwang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.com0tag:blogger.com,1999:blog-2780729719074003466.post-58107221535083387582010-02-01T17:24:00.000-08:002010-02-03T17:27:18.951-08:00pointer arithmentica[99]={.....}<br />short int* p = a;<br />short int** q = &p;<br /><br />p++;//this means that pointer position increase one so that a[0] become a[1]<br />(*p)++;//this means that the value the pointer is pointing to increase one.<br /><br /><br />(*q)++;//means pointer p add 1 position so a[1] move to a[2]<br /><br />(**q)++//means value of pointer q pointing to add one so the value the pointer p point to add 1wang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.com0tag:blogger.com,1999:blog-2780729719074003466.post-2438445866990805102010-01-24T17:58:00.000-08:002010-01-24T18:05:33.336-08:00svn command on linux1.svn --help <br />List Subversion commands<br />2.svn help command Also: ? or h <br />Help on given "command" <br />3.svn add filename <br /> svn add directory<br />Add a file or directory to Subversion CM control.<br />Must also perform: svn ci filename (or svn commit) to upload the file or directory. File will not be available in the repository until a "commit" is performed. If adding a directory, the directory and all of its contents recursively are added. i.e.:<br />svn ci directory<br />svn commit directory<br />svn commit .<br />4.svn cleanup<br />Cleanup subversion files resulting from escaped processes and crashed.<br />5.svn commit filename<br />svn commit --message "Message goes here." filename<br />svn commit -m "Message goes here." filename<br />svn ci filename1 filename2 filename3<br />svn ci .<br />Check-in (commit) local "working" file, files or directory and contents (recursively) into Subversion repository. Atomic, i.e. all committed or none, no incomplete check-in.<br />6.svn diff filename<br />svn di filename<br />Show file diffs between SVN repository and your file changes using GNU file diff format. Use GUI diff tools as shown below.wang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.com0tag:blogger.com,1999:blog-2780729719074003466.post-1036462960390589872010-01-16T18:08:00.000-08:002010-01-16T18:34:44.055-08:00Review for previous classPrefix increment vs Postfix increment<br />int main(){<br />int a=0;<br />int b=0;<br />int c=0;<br />c = a++ + 36;//c will be 36 a will be 1. a is 0 and when this operation finish a get //added <br />printf("%d",c);<br />}<br /><br />int main(){<br />int a=0;<br />int b=0;<br />int c=0;<br />c = ++a + 36;//c will be 37 a will be 1. before operation a get added and affect //result<br />printf("%d",c);<br />}wang conghttp://www.blogger.com/profile/16799167968649436638noreply@blogger.com0