DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Java
  4. Display Static Google Maps in a Java Desktop Application

Display Static Google Maps in a Java Desktop Application

A. Programmer user avatar by
A. Programmer
·
Dec. 15, 11 · Interview
Like (0)
Save
Tweet
Share
8.79K Views

Join the DZone community and get the full member experience.

Join For Free

Displaying static Google Maps in a Java desktop application sounds complicated, since iGoogle Maps provide a JavaScript API that can be exploited from web pages based on a Google key per host. Besides this API, Google Maps also provides a URL based API for extracting static Google Maps directly into desktop application, without requiring JavaScript or access keys. This API is explained very well here: http://code.google.com/apis/maps/documentation/staticmaps/index.html.


Based on this tutorial, Java can extract and save a Google Maps static map in just a few lines of code, without any high complexity involved. Even though the API is very simple, it took me a while to get to this API, so I will share my code here:

try {
    BufferedImage img = ImageIO.read(new URL("http://maps.googleapis.com/maps/
    api/staticmap?sensor=false&size=512x512¢er=Brooklyn&zoom=12&style=feature:
    road.local%7Celement:geometry%7Chue:0x00ff00%7 Csaturation:100&style=feature:  
    landscape%7Celement:geometry%7Clightness:-100"));
    
    File outputfile = new File("map.png");
    ImageIO.write(img, "png", outputfile);
    System.out.println("Saved!");
    } catch (Exception ex) {
         System.out.println("Error!" + ex);
    }
The map below is taken from Google Maps, and it looks as follows:

 

From http://e-blog-java.blogspot.com/2011/12/display-static-google-maps-in-java.html

Google Maps Google (verb) application Desktop (word processor) Java (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Testing Level Dynamics: Achieving Confidence From Testing
  • 11 Observability Tools You Should Know
  • Top 5 Data Streaming Trends for 2023
  • Microservices Testing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: