Web map service java

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Java client library for Google Maps API Web Services

License

googlemaps/google-maps-services-java

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Bumps [com.google.appengine:appengine-api-1.0-sdk](https://github.com/GoogleCloudPlatform/appengine-java-standard) from 2.0.15 to 2.0.16. — [Release notes](https://github.com/GoogleCloudPlatform/appengine-java-standard/releases) — [Commits](GoogleCloudPlatform/appengine-java-standard@v2.0.15. v2.0.16) — updated-dependencies: — dependency-name: com.google.appengine:appengine-api-1.0-sdk dependency-type: direct:production update-type: version-update:semver-patch . Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot]

Git stats

Files

Failed to load latest commit information.

README.md

Java Client for Google Maps Services

Use Java? Want to geocode something? Looking for directions? Maybe matrices of directions? This library brings the Google Maps API Web Services to your server-side Java application.

The Java Client for Google Maps Services is a Java Client library for the following Google Maps APIs:

Keep in mind that the same terms and conditions apply to usage of the APIs when they’re accessed through this library.

Each Google Maps Web Service request requires an API key. API keys are generated in the ‘Credentials’ page of the ‘APIs & Services’ tab of Google Cloud console.

For even more information on getting started with Google Maps Platform and generating an API key, see Get Started with Google Maps Platform in our docs.

The Java Client for Google Maps Services is designed for use in both server and Android applications. In either case, it is important to add API key restrictions to improve the security of your API key. Additional security measures, such as hiding your key from version control, should also be put in place to further improve the security of your API key.

Читайте также:  Executing python programs in windows

You can refer to API Security Best Practices to learn more about this topic.

NOTE: If you are using this library on Android, ensure that your application is using at least version 0.19.0 of this library so that API key restrictions can be enforced.

You can add the library to your project via Maven or Gradle.

Note: Since 0.1.18 there is now a dependency on SLF4J. You need to add one of the adapter dependencies that makes sense for your logging setup. In the configuration samples below we are integrating slf4j-nop, but there are others like slf4j-log4j12 and slf4j-jdk14 that will make more sense in other configurations. This will stop a warning message being emitted when you start using google-maps-services .

dependency> groupId>com.google.mapsgroupId> artifactId>google-maps-servicesartifactId> version>(insert latest version)version> dependency> dependency> groupId>org.slf4jgroupId> artifactId>slf4j-simpleartifactId> version>1.7.25version> dependency>
repositories < mavenCentral() >dependencies < implementation 'com.google.maps:google-maps-services:(insert latest version)' implementation 'org.slf4j:slf4j-simple:1.7.25' >

You can find the latest version at the top of this README or by searching Maven Central.

Additional documentation for the included web services is available at https://developers.google.com/maps/.

This example uses the Geocoding API with an API key:

GeoApiContext context = new GeoApiContext.Builder() .apiKey("AIza. ") .build(); GeocodingResult[] results = GeocodingApi.geocode(context, "1600 Amphitheatre Parkway Mountain View, CA 94043").await(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); System.out.println(gson.toJson(results[0].addressComponents)); // Invoke .shutdown() after your application is done making requests context.shutdown();

Note: The GeoApiContext is designed to be a Singleton in your application. Please instantiate one on application startup, and continue to use it for the life of your application. This will enable proper QPS enforcement across all of your requests.

At the end of the execution, call the shutdown() method of GeoApiContext , otherwise the thread will remain instantiated in memory.

For more usage examples, check out the tests.

Google App Engine Support

To use Google App Engine with this client library add the latest App Engine dependency to your build.gradle file:

dependencies < implementation 'com.google.appengine:appengine-api-1.0-sdk:' >

You can then use this client library on Google App Engine with the following code change:

new GeoApiContext.Builder(new GaeRequestHandler.Builder()) .apiKey("AIza. ") .build();

The new GaeRequestHandler.Builder() argument to GeoApiContext.Builder ‘s requestHandlerBuilder tells the Java Client for Google Maps Services to utilise the appropriate calls for making HTTP requests from Google App Engine, instead of the default OkHttp3 based strategy.

Never sleep between requests again! By default, requests are sent at the expected rate limits for each web service, typically 50 queries per second for free users. If you want to speed up or slow down requests, you can do that too, using new GeoApiContext.Builder().queryRateLimit(qps).build() . Note that you still need to manually handle the delay between the initial request and successive pages when you’re paging through multiple result sets.

Читайте также:  Public member class java

Automatically retry when intermittent failures occur. That is, when any of the retriable 5xx errors are returned from the API.

To alter or disable automatic retries, see these methods in GeoApiContext :

  • .disableRetries()
  • .maxRetries()
  • .retryTimeout()
  • .setIfExceptionIsAllowedToRetry()

Native objects for each of the API responses.

Asynchronous or synchronous — you choose

All requests support synchronous or asynchronous calling style.

GeocodingApiRequest req = GeocodingApi.newRequest(context).address("Sydney"); // Synchronous try < req.await(); // Handle successful request. > catch (Exception e) < // Handle error > req.awaitIgnoreError(); // No checked exception. // Async req.setCallback(new PendingResult.CallbackGeocodingResult[]>() < @Override public void onResult(GeocodingResult[] result) < // Handle successful request. > @Override public void onFailure(Throwable e) < // Handle error. > >);

Note: You will need an API key or Client ID to run the tests.

# Compile and package the project $ ./gradlew jar # Run the tests $ ./gradlew test 

This library is community supported. We’re comfortable enough with the stability and features of the library that we want you to build real production applications on it. We will try to support, through Stack Overflow, the public and protected surface of the library and maintain backwards compatibility in the future; however, while the library is in version 0.x, we reserve the right to make backwards-incompatible changes. If we do remove some functionality (typically because better functionality exists or if the feature proved infeasible), our intention is to deprecate and give developers a year to update their code.

If you find a bug, or have a feature suggestion, please log an issue. If you’d like to contribute, please read How to Contribute.

About

Java client library for Google Maps API Web Services

Источник

Web map service java

The coordinate system of GeoServer should correspond to the atlas coordinate system of the ArcGIS sliced ​​data one by one, otherwise the position will be disordered. The coordinate system on the left can be found in the .prj file of the atlas, and the coordinate system on the right is required by GeoServer. These are currently commonly used.

2. An error is reported when publishing atlas (indicated by clicking OpenLayers to directly download an empty file):

  • May be related to style, check the encoding. I encountered a big pit. The .sld file with Chinese modified on windows will be garbled when copied to linux, causing the atlas to report errors.
  • It may be related to the content of the zip file (try to use .zip, rar cannot solve the problem of low version). The zip compressed file must be the first level directory with .shp and other files, and cannot contain directories
  • The issue of obtaining the URL publishing address. You can read the path where the local Geoserver is located, add the name of the published workspace, and splice the layer id to the url.
import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.ResourceBundle; /** * 

* xml parsing tools *

* * @author liugh * @since 2018/4/3
*/ public class XmlUtil private static String GEO_SERVER_PATH = ResourceBundle.getBundle("constant").getString("geoServer-dir"); private static String BUNDLE_URL = ResourceBundle.getBundle("constant").getString("geoServer-url"); private static String XML_ELEMENT_NAME="latLonBoundingBox"; public static void main(String[] args)throws Exception < getMapUrl("1522723368940","unitMap"); > //Get atlas publishing address public static String getMapUrl(String layerId,String workspace)throws Exception< File file =new File(GEO_SERVER_PATH+File.separator+workspace); String[] fileList = file.list(); StringBuilder mapUrl = new StringBuilder(); mapUrl.append(BUNDLE_URL+workspace) .append("/wms?service=WMS&version=1.1.0&request=GetMap&layers=").append(workspace+":"+layerId).append("&styles=&bbox="); if(!ComUtil.isEmpty(fileList)) for (String fileName:fileList) if(fileName.equals(layerId))< String [] coordinates = readXMLDocument(layerId,workspace); mapUrl.append(coordinates[0]+","+coordinates[2]+","+coordinates[1]+","+coordinates[3]).append("&width=768&height=437&srs=").append(coordinates[4]); > > >else return null; > return mapUrl.toString(); > private static String [] readXMLDocument(String layerId, String workspace)< File file = new File(GEO_SERVER_PATH+File.separator+workspace+ File.separator+layerId+File.separator+layerId+File.separator+"featuretype.xml"); if (!file.exists()) try throw new IOException("Can't find the path"); > catch (IOException e) < e.printStackTrace(); >> //Create SAXReader object SAXReader saxReader = new SAXReader(); Document document; try //Read file and convert to Document document = saxReader.read(file); //Get the root node element object, traverse all nodes under the current node for (Iterator iter = document.getRootElement().elementIterator(); iter.hasNext();) //Get node Element e1 = (Element) iter.next(); //If the name of the passed node is equal to beanName, then continue to enter the loop to read all nodes under the beanName node if(e1.getName().equalsIgnoreCase(XML_ELEMENT_NAME))< String [] ss = new String[5]; int i =0; //Traverse all nodes under the current node of beanName for (Iterator iter1 = e1.elementIterator(); iter1.hasNext();)< Element e2 = (Element) iter1.next(); ss[i]= e2.getStringValue(); i++; > return ss; > > > catch (DocumentException e) < e.printStackTrace(); return null; > return null; > >

3. Filtering attribute issues.

When the mouse clicks on a certain area of ​​the map published by GeoServer, the properties will be displayed below. Here I get all the values ​​through Http, and then use Jsoup to parse, similar to the way of crawling. After returning the attributes, you can block or display some attribute values ​​according to the business.

import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 

* HTTP request tools *

* * @author liugh * @since 2018/3/20
*/ public class HttpLayerPropertyUtil /** * Get all the attributes of the layer * @param layerPreviewURL * @return */ public static List> getLayerProperty(String layerPreviewURL)< List> retList = new ArrayList(); try < Document doc = Jsoup.connect(layerPreviewURL).get(); Elements select = doc.select("th"); Elements select1 = doc.select("td"); for (int i = 0; i < select.size(); i++) < HashMap tempMap = new HashMap<>(16); tempMap.put(cutValue(select.get(i).toString()), cutValue(select1.get(i).toString())); retList.add(tempMap); > return retList; > catch (IOException e) < System.out.println("The page gets abnormal!"); e.printStackTrace(); > return null; > private static String cutValue(String s)< String substring = s.substring(4,s.indexOf("")); return substring; > >

Источник

Оцените статью