Results 1 to 7 of 7
  1. #1
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Help with parsing website with regex please

    I want to add google maps direction to my program (its free to add it to your website so it shouldnt be a problem)

    But the problem is that the code they give you (although working on the demo example) doesn't work when you put it in your website. It has some error in the JS file which you are linking but can't access. So anyway I decided to do it manually.

    To get directions with google maps, you need to use this URL:

    Java Code:
    http://maps.google.com/maps?
    saddr=stanyan+st%2C+san+francisco
    &daddr=twin+peaks+blvd%2C+san+francisco
    
    where saddr= is followed by the Start ADDRess
    and daddr= is followed by the Destination ADDRess
    It loads up a google map search page with the directions to the left. Its too much for me, I only need the direction text. So I had a look at the code and found that the page contains the information i need like this:

    Java Code:
    Directions title * needs to be found like this: "<div id=\"dir_title\">*</div>"
    
    Directions instructions need to be found between the first instance of:
    "<td class=\"dir-cb-cbicon\">"
    
    and the last instance of:
    "<td class=\"dir-cb-cbicon\">"

    So first I need to download the URL.
    Java Code:
    //compile URL
    String mapURLstr = "http://maps.google.com/maps?saddr=" + DIR_START + "&daddr=" + DIR_FINISH;
    URL mapURL = new URL(mapURLstr);
    FIRST QUESTION
    obviously the URL needs to be in the form where spaces are replaced with '+' and commas replaced with '%2C', so is there are java package built in to convert a string to a URL-friendly URL, or will this not be a problem by invoking new URL(urlString); ?

    Java Code:
    //download page to parse
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mapURL.openStream()));
    //rebuild page
    String s;
    StringBuilder builder = new StringBuilder();
    while ((s = bufferedReader.readLine()) != null) {
        builder.append(s);
    }
    String mapHTML = builder.toString();
    SECOND QUESTION
    How do I use the regex patterns to extract the required information as stated at the beginning of this post or delete the unwanted information from the String 'mapHTML'?

    Thanks for your help
    Last edited by ozzyman; 04-08-2011 at 06:43 PM.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Quote Originally Posted by ozzyman View Post
    I want to add google maps direction to my program (its free to add it to your website so it shouldnt be a problem)
    Mhm i think thats not correct! Its even forbidden to use the official direction API without a google map!
    The Google Directions API - Google Maps API Web Services - Google Code
    "[...]Note: the Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited. Additionally, calculation of directions generates copyrights and warnings which must be displayed to the user in some fashion.[...]"

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Ohh I see, well thanks for that. So I guess it isn't allowed unless I show the map too. But I don't think they'd find out :S. All i'm doing is downloading their page to my hard drive, its like opening a web browser. Once the page is on my hard drive, I'm just doing myself the pleasure of showing myself only the parts that I need.

    Oh and I just remembered, I AM going to show the map with it, only I'm going to use the STATIC map address because its lighter and loads faster and doesnt contain any javascript. So it will be fine.

    Check this link out to see what i'm talking about:
    Driving Directions Gadget

    its a compact tool for your website which doesn't contain the whole page as such, it just shows the directions + an interactive map.

    What i'm planning on doing is getting the same thing, but directions + static map, manually.

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Are you talking about a webapplication or a desktop application?

    Google Maps/Google Earth APIs Terms of Service - Google Maps API Family - Google Code
    "[...](h) No Use of Static Maps API(s) outside a Web-Based Application (Except with a Link to Google Maps). You must not use the Static Maps API(s) outside of a web-based application unless:

    (i) your platform does not have a web browser; or

    (ii) if your platform does have a web browser, you provide a link that shows the location concerned either (x) in the Google Maps native application (if your platform has one); or (y) on the Google Maps website.[...]"

    ;)

    I recommend you to use the API of CloudMade.com ;)

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    really, all i need is a simple map with simple directions. i looked at CloudMade.com's Mapzen, its too much for me.

    its for a desktop application. the number of requests would never exceed 2,500 requests per day so it would never be enough for google to look into how i'm using their data. furthermore, the desktop application i plan on using on different computers (with different IPs) so each copy would have its own limit of 2,500 because it is simple downloading the website AS IS so there is no noteable difference in how the page is being viewed Except the web browser. (if a java application downloads a webpage, what does the browser name come up as if you had a browser sniffer?)

  6. #6
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    does anyone have any guidance regarding the extraction of data with regex from the string?

  7. #7
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

Similar Threads

  1. need help with regex
    By o2a1 in forum New To Java
    Replies: 3
    Last Post: 02-13-2011, 12:53 AM
  2. Regex help?
    By l3ane in forum New To Java
    Replies: 6
    Last Post: 01-18-2011, 06:04 AM
  3. Using Regex
    By ron87 in forum New To Java
    Replies: 4
    Last Post: 09-12-2010, 06:26 AM
  4. Please Help - Regex
    By BeeGee in forum Advanced Java
    Replies: 0
    Last Post: 04-28-2010, 05:28 PM
  5. How to download website (Get all link in website)
    By finalmem in forum Advanced Java
    Replies: 0
    Last Post: 11-12-2008, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •