File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Google Maps and JSON Geocoding Output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Google Maps and JSON Geocoding Output" Watch "Google Maps and JSON Geocoding Output" New topic

Google Maps and JSON Geocoding Output

Brandon Golway

Joined: Oct 19, 2010
Posts: 23
I'm pretty bad with javascript and I need help with overlaying the data I get back from Google's static geocoding API. Here's the API link already formed to convert New York,NY to 40.78343450, -73.96624950,NY%22&sensor=false but after a few hours of messing with it, I can't figure out what to do with it and where to put it. Should it go in my html source where my map is? Should it go in my PHP file since the locations for geocoding will come from the PHP file? Should it go in it's own external file?

I tried using jQuery.parseJSON in my main html page but couldn't figure out how to get any output from it. Google also says that you can easily parse out the location coordinates by using this script, but I have no idea what to do with it either.

Could someone please write an example on how to take the JSON data, parse it so there's only location data, and make it available to the Google Maps API so that I can place a marker? I can't find anything that gives implementation examples or details, just how to do it if you already know what you're doing, which I obviously don't. I based my stuff off of Google's HTML example files but they don't have one for static geocoding, only dynamic geocoding (which is apparently built into the maps API).

Here's a basic road map of what I'm trying to do:

1. use scraper.php to scrape city and state from a job listing site into an array (done)
2. strip the 25 locations out of the array one at a time using a for loop (done)
3. feed those individual strings into the geocoding API url (done)
4. Parse the JSON output from the geocoding API URL and grab the coordinates from the location field, then overlay them on the map (this is what I need help with)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Which map API are you using? Your mention of PHP makes me think that you are not using the JavaScript V3 API -- which is the only one I've used, and as I recall, was pretty straight=forward (as in, no JSON parsing necessary).

[Asking smart questions] [About Bear] [Books by Bear]
Brandon Golway

Joined: Oct 19, 2010
Posts: 23
This is what I followed to implement the map: Google Maps Javascript API V3 Tutorial. Once I understood it, it was pretty easy to implement the map and it's features. I need to Statically Geocode Locations which have been previously scraped by a PHP scraper (along with job title and a link to the job), then placed on the map with a marker and info bubble that will open when clicked containing the company name, the title of the job, and possibly a link to the job.

The output of the geocoder is either JSON or XML and Google recommends JSON since the code is more concise and its easier to pick stuff out that you want.
I agree. Here's the link:
subject: Google Maps and JSON Geocoding Output
It's not a secret anymore!