I have a KML in the form of a string. Actually I call a service from my GWT project and the service returns a KML file in the form of a string. How can I present this KML on my map? All I have is a string. Should I first parse it or can I create a KML layer from this string?
//I'm using google maps v3 api for GWT
I thought you were working in JavaScript, but since you are working in Java, have you taken a look at the JAK Java API for KML? It uses JAXB under the covers, but it provides an unmarshal function that accepts either a file or a String. There is an article describing the library on TheServerSide.com and another article on Java.net.
And finally, there is some good and detailed documentation available at Micromata's JAK site. Hope this helps -
I'm trying to do the exact same thing you are. Check out this example from Google: KmlOverlayDemo.java.
You will have to write the string to a file (this would be best done on the server side) and then call GeoXmlOverlay.load("KmlFilePath", GeoXmlLoadCallback). If successful, an overlay object is returned that you can just add to the MapWidget.
This is the best way I've found so far, but I'm searching for a better way.
Related
I am looking to use this JSON interface:
https://translate.yandex.net/api/v1.5/tr.json/translate ?
key=<API key>
& text=<text to translate>
& lang=<translation direction>
& [format=<text format>]
& [options=<translation options>]
& [callback=<name of the callback function>]
More info
It returns a JSON object. How do I get that JSON object in Java?
I know there already is an implementation for that exact API, but it's old and not working anymore.
I've had good results using google's gson library. Really this depends on what you are doing with the JSON data - is it a rest payload, JMS message or what? A lot of stuff understands JSON natively now so don't reinvent the wheel.
Yandex.Translate API documentation can be found here:
With the API, you can access the online machine translation service Yandex. It supports more than 60 languages and can translate single words and whole texts. This API allows you to embed Yandex.Translate in a mobile application or web service for end users. Or, to translate large volumes of text - such as technical documentation.
Firstly , this is a java program but not Android.
I write a very simple API to get the DB data in Php like below code:
<?php
$query = "Select * from staff order by staff_name";
$reuslt = $mysqli->query($query);
echo json_encode($reuslt->fetch_object());
Suppose that i can get the JSON object in the following URL easily in Android or Php:
http://localhost/Testing/simpleWebService.php
But how can i get it in Java??
I have searched it in Google but the result seems not what i actually want and useful to me
(Reason is i am quite Junior to Java ,Lack of knowledge in Web Service, not accurate keywords inputted........).
I found sth like Jersey, JAX-RS but i don't think this help and the way to get the JSON from the Web Service is complex like that.
Can anyone help ? Thank you very much!!!!!!
The crux of the matter is that you have to replace the behaviour implemented by PHP's json_encode function in Java ie. you have got to find a way to convert the recordset representation of your data to JSON.
1 approach would be to manually convert your recordset to a collection of POJO's then use Jackson to generate the JSON.
However, there are loads of frameworks that make this easier for you to achieve.
What Java framework are you using as that will constrain your future decisions to some degree? How are you reading from your DB - using JDBC API or using an ORM or other library?
There's a lot of info out there for a newbie like myself when it comes to webservices, I acknowledge that.
However, most of the Google results I've seen tend to be focusing on a specific format or strategy, and all of them different to each other.
As a newbie, I am looking to get more of an overview of the various options open to me, their pros & cons... before I start committing to a specific one.
For example, I have an existing webservice created from a SQL Server source via ASP.net and this by default comes out as a DiffGram. So there are articles that tell me how to parse the diffgram data coming into my Android app, but I still do not know if the diffgram is the best option I should be using in the first place.
Should I, for example be changing my webservice to output JSON ?
Does anyone know of a 101 level tutorial or explanation out there ?
Many Thanks
DiffGram is just another type of XML format. In order to parse the XML data in Android, simply use the XMLFullParse class.
FYI: http://developer.android.com/training/basics/network-ops/xml.html
However if you just want to create a simple data exchange WebService, Json is definitely a better choice. Json is simple, lightweight, easier-to-parse and surely easier to use.
Example:
JsonObject json = new JsonObject(jsonString);
json.put("name", "Michael");
json.put("age", "18");
String name = json.opt("name");
i was trying to call a .net webservice with the Android SDK, that was simple using the ksoap2 library, including passing and getting complex types.yet i faced a more complicated problem, the
SoapSerializationEnvelope.getResult()
or SoapSerializationEnvelope.getResponse() only gives the return value of the web method, but when there is out parameters in the method, how can i get them?
i found a work arround to get them by setting the AndroidHttpTransport.debug=true and thus being able to get AndroidHttpTransport.responseDump and then parsing this xml string and get the values out of it the thing is that isn't there any simpler way to get these out parameters?
excuse me for the bad formatted question, but this is my first time using it:S..
Thanks in advance
See my answer to How to retrieve binary data from Web Service in Android?
It shown how to access the response parameters.
I'm looking for a good web framework for compositing multiple JSON sources fetched with HTTP requests in to static HTML. I am not looking to do this on the client-side (browser, javascript), I am looking for the best server-side solution.
So, what I need to do is:
Fetch several different JSON documents over HTTP
Format that JSON as HTML content, mostly with templates but some dynamic custom HTML
Basic login/logout/preferences customization, nothing major
Mostly stateless pages; what state there is, comes already in the JSON
User / search engine friendly / bookmarkable URLs; should be customizable accurately
How I'd like to do it:
A lean solution, perhaps just a template engine
HTML templates that have no custom syntax over HTML/XML, like Wicket and almost like Tapestry
Application server that is scalable and utilizes multiple CPUs properly (for example, a single Python process does not)
Preferably Java, but if Java doesn't have anything that fits, willing to consider others
As for the template part, if this were to be in JavaScript in the browser, something like PURE would be my tool of choice.
You might want to check out RESTx. That's an open source platform for the easy creation of RESTful resources. It allows you to write custom data access and integration logic in either Java or Python. Getting data from multiple sources and combining them is what it's made for, so this should be a pretty close fit. Data output is rendered according to what the user requested. For example, a further JSON data source, or the same data rendered in HTML.
The HTML rendering is currently according to a built-in template. However, that should be easy enough to modify. I'm one of the developers on that project, so if you need some special template functionality, let me know and I will see what I can do.
To give you an example: Assume you have two JSON resources, in your code you would write this (I'm giving a Python example here, but the Java example would look very similar):
status, data_1 = accessResource("/resource/some_resource")
status, data_2 = accessResource("/resource/some_other_resource")
# data_1 and data_2 now hold a dictionary, list, etc., depending on the JSON
# that was returned.
# ... some code that combines and processes the data and produces a dict or list
# with the result. The data object you return here is then automatically rendered
# in either HTML or JSON, depending on the client request.
return Result.ok(data)
Also take a look at the example for some simple data integration here.
I think that the only framework you need is a library that reads json. The templates can very well be standard jsp pages.