Ahmed Mansy
Ahmed Mansy

Reputation: 25

How to use Google maps inside servlets?

I'm new to servlet and jsp, I want to make a simple application using Java servlets or JSP that get the locations of some places using Google maps and then do some calculations, then display the results on the map in a webpage. I can request places search using this :

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522%2C151.1957362&radius=500&types=bus_station&sensor=false&key=YOURAPIKEY.

It returns a JSON array, but I don't know how to call this link inside java code. or how to send the location from java-script to servlets.

Simply I want to apply algorithm written in java and calls data from Google maps also return outputs on map.

Upvotes: 0

Views: 4261

Answers (3)

Alexander Sidikov Pfeif
Alexander Sidikov Pfeif

Reputation: 2435

Integrating Maps into Your Java Web Application with Google Maps and Ajax (V2 !!)

https://today.java.net/pub/a/today/2006/10/25/integrating-google-maps-into-web-application.html

Upvotes: 0

Arjun Sol
Arjun Sol

Reputation: 741

Use HTMLUnit: http://htmlunit.sourceforge.net/

It will simulate browser action so you can post whatever you want and have an appropriate method handle the callback.

  WebClient webClient = new WebClient();
  webClient.setThrowExceptionOnScriptError(false);

  try {
     UnexpectedPage page = webClient.getPage(url);
     InputStream inputStream = page.getInputStream();
     // Read the stream
  } catch (IOException e) {
     e.printStackTrace();
  }

Upvotes: 0

Neil
Neil

Reputation: 6039

You can use URLConnection to call the link from Java code and XMLHTTPRequest to send the location from browser (javascript) to the servlet.

Upvotes: 1

Related Questions