Mysql ,JSP ,Google Maps - mysql

I have explored some of the interesting Google Maps Tutorials.I am interested to show Info Window and Markers on custom Google Map on my application.Where i want to get data for info Window and markers from MySQL and instead of using php i want to use JSP.
I have searched a lot on Google.I did not find any particular solution for this.Can anyone help me or give me hint on how i should go for it? Or Do I have to learn php now? Because i am good in JSP.
Any help would be more appreciable.
Thanks in advance.

I am glad to answer my own question which was posted on stack overflow approximately 7-8 months back.
Question :- I wanted to display google map and some google map features in jsp (Not in PHP). Features such as InfoWindow etc.
Problem :- All GoogleMap feature logic was present in JavaScript. So I wanted to get my business data(which might contain some lat and longs) from mysql db inside javascript and show that data inside infowindow or use that data to put some markers on google maps etc. All this I wanted to do inside JSP's javascript.
Solution :- There are 2 solutions I found out
1) Use servlet which will return you data which you need in json format and call that servlet url inside javascript using ajax calls.
2) Use Spring MVC. Spring MVC return json object with #ResponseBody annotation specified inside your controller's method and you just have to call that url in same way as we will call servlet inside javascript using ajax call.
sample Ajax function :-
$.ajax({
type: "post",
url: "/ServletReturnJson/JsonServlet",//URL to your servlet
dataType: 'json'
success:function(msg) {
var m=msg;
var json = m ,
obj = JSON.parse(json);
for(var i=0;i<obj.length;i++){
//Iterate your data
}
});
Note :- Above is just sample. You can try with your own classes and use above sample as guideline.

My suggestion would be to read and understand this tutorial. Implement the concept using JSP rather than PHP.

Related

beginner: Json Result serialization in a asp.net mvc page without jquery/javascript/ajax

i am a programming student, working with a asp.net mvc 4 web app, i am testing a simple web app that uses the http://openweathermap.org/api so when i click a link, it executes the Action Result on the home controller, the code to get the data from the api is in this action result and it fetches the api json data and stores it in a viewbag.message that is then passed back to the view. I have that much working in so far as i can get the json result and see it on the view. I am not sure how to proceed & the pages i have looked up seem to be centered around ajax jquery
My question is about the serializing/displaying the json result without adding any plugins or anything just yet, i would like to format / serialise it so it looks better maybe fit it into a table or something, but without getting into ajax & jquery just yet as i haven't learned that part yet.
I have removed the api key from the code.
public ActionResult getWeather()
{
var uri = "http://api.openweathermap.org/data/2.5/forecast?id=7778677&APPID=123456789";
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
var resultContent = client.DownloadString(uri);
ViewBag.Message = resultContent;
return View();
}
And here is the result view:
screenshot of result view showing the json data from the api
I hope i am explaining myself correctly,
Thank You.
M.
.NET 4 has a built-in JSON serializer/deserializer, but if you can, use NuGet to get NewtonSofts JSON Framework as it is much more flexible and powerful.
With it, you could do something along the lines of this within your backing code for your view, or maybe even in your view's template with Razor:
WeatherDataModel[] myWeatherData = JsonConvert.DeserializeObject<WeatherDataModel>(ViewBag.Message);
(This assumes you have a model for the weather data that matches up with the data you get from the openweathermap api.)
You should then be able to use a loop to get the data in your WeatherDataModel array into a table.
Another option, if you are willing to take a small leap into jquery, can be found in the answer to this question:
How to load JSON data into Bootstrap table?
It makes use of a very simple snippet of javascript/jquery and bootstrap.
In your case, you would set the data to use the JSON you stored in the ViewBag.Message:
$(function () {
$('#table').bootstrapTable({
data: ViewBag.Message
});
});
If you built your app in VS 2015 and used the MVC 4 template, you may very well already have bootstrap built into your project. If not, you can easily import it with NuGet.
I haven't done much in MVC 4 for a while now, and so I will point you to this question's answer about where best to place your scripts: Proper place to load jQuery in MVC Layout view
Good luck!

use JSON api for live news

I have this Fox Sport API url :
https://newsapi.org/v1/articles?source=fox-sports&sortBy=top&apiKey=955acf3993df49169dfa33dce76d015f
How do i use this? I know it's based on Json. But where do i put this URL? in what format or file? Can someone please help me?
I alrady tried putting it between scripts tags in my index.php file but no results...
Thank you!
Google it ---> Php curl. Read the doc!
If you are using a framework, let us know which one😃
JSON is simply a useful way to send and receive strings that represent objects in JavaScript. In these days I'm working on an application that uses JSON strings to store and retrieve data, and I found a very simple way to get data from JSON strings, that is jQuery. This library has a jQuery.getJSON() method, which let you to load JSON-encoded data from the server (or locally) using a GET HTTP request. Here you can find all the details you need to use this method.
Obviously you could choose not to use any third-part library and do what you need in vanilla JavaScript, but jQuery is very useful since it helps to avoid common cross-browser issues.
In my application I store data from a JSON string in this way:
var placesList;
jQuery.getJSON("places.txt").done(function (data) {
placesList = data;
});
that is using an external variable to store them using an anonymous function. As you can see, my URL here is places.txt, but you can use any valid URL you want that provide a JSON string.
You should try like this -
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var url = 'https://newsapi.org/v1/articles?source=fox-sports&sortBy=top&apiKey=955acf3993df49169dfa33dce76d015f';
$.getJSON(url).then(function(res){
console.log(res) //{status: "ok", source: "fox-sports", sortBy: "top", articles: Array[10]}
console.log(res['status']) //ok
console.log(res['source']) //fox-sports
console.log(res['sortBy']) //top
console.log(res['articles'].length) //10
})
})
</script>

Using xamarin to retrieve JSON message from URl and show in table view

I'm started developement in xamarin cross platform development in visual studio. I want to know, how to retrieve the JSON message from url to show the details in table view. Here i give a sample url, how to retrieve all the city name in the json data and show in table. Help me!
url: http://api.wunderground.com/api/02e5dd8c34e3e657/geolookup/conditions/forecast/q/Dhaka,Bangladesh.json
As #Udi said, your question is too broad. But because of that, I'll give broad answers.
First, use HttpClient to retrieve the data from your url. Second, use Json.Net to deserialize your response into your entities/model.
string url = #"http://api.wunderground.com/api/02e5dd8c34e3e657/geolookup/conditions/forecast/q/Dhaka,Bangladesh.json";
using (var client = new HttpClient())
{
var result = await client.GetStringAsync(url);
return JsonConvert.DeserializeObject<YourModelForTheResponse>(result);
}
Third, to display your data, I would suggest going Xamarin.Forms or MonoTouch.Dialog. It makes using tables way easier.
I have a sample app that I queried a service, got a json response, and displayed the list of data using both Xamarin.Forms and MonoTouch.Dialog. Check out my sample app at github.
I posted this question on xamarin forums with complete coding. I got a answer from someone with complete coding structure. Its work for me.
click here to see the link with question and answer. I hope, it works for all u.

Pass Json Object from Play! framework to HighCharts JS

http://www.playframework.com/documentation/2.1.x/JavaTodoList
Using the above tutorial as a reference, I have created an application which sends data from the model to view via the Application controller.
I have managed to display the model(Tasks) as a high chart. The code is here.
public static Result format(){
return ok(views.html.frmt.render("Visualize it",Task.all()));
}
This goes to this view page.
http://ideone.com/ycz9ko
Currently, I use scala templating inside the javascript code itself. Refer to lines 9-14 and lines 20-24.This unelegant style of doing things is not really optimal.
I want to be able to accomplish the above using Json instead.
public static Result jsonIt(){
List<Task> tasks = Task.all();
return ok(Json.toJson(tasks));
}
My Qns are how to send the JSON objects to a view template.
And how to parse it into a Highcharts format. Is there some standard procedure to do this ? Or else I have to write my own method to do this ?
It'll great if someone can show me a code snippet. Also I would prefer a post not using Ajax. I would just want to know how to do this first.
I also found this stackoverflow post useful.how to parse json into highcharts. However, it didnt answer the part about converting from Play format to Highcharts format.
Thanks in advance
You don't need to pass a json object to your template, instead you might do an ajax call from your client side javascript (your template) and get json response that you could use futher in javascript code to build a chart. For example :
You have some path that is bind to your controller jsonIt() like so /chartsdata/json
then using jquery shorthand for ajax request:
var chart_data = $.get('/chartsdata/json', function(data) {
return data;
});
now you can use a chart_data that is an array of objects where each object represents a Task, in your further javascript code to build a chart.

LDAP Java EE, Auto-complete with jquery-ui and json object by servlet?

I am developing a java web program that can manage distant ldap entries,
we have to select person and i want to do this with auto-complete text-area functionality
I have Java function to return the entire list, to find by name or just by the begin of the name (wildcard search, spring ldap).
My idea was to use the jQuery ui autocomplete plugin, but I don't know how to catch remote source.
I think that must be by json object return by a servlet
Anyone know how can I do that?
I hope that's not to hard to implement
thank in advance for help
So I assume you are successfully getting the data retrieved from the LDAP using spring security.
All you need to do is to convert the data into JSON. If you are not using any json library already, you can use json.org for simplicity (or any other jsob-library).
Create a servlet that accepts request param term. call your LDAP Search based on this term. Create a json array of the result and print that that on response in doGet(). Map the servlet to desired path
$( "#your-element" ).autocomplete({
source: "/servlet/path",
minLength: 2
});