Calculating Distance using Google maps API & passing value between javascript and C# - google-maps-api-3

I am using Google maps API for the first time hence facing few difficulties and need help.
I have a requirement to find distance between few points and keep them saved for later use.
Below is the exact scenario and problem i am facing.
I am using Latitude, longitude data that i have to find distance.
Scenario:
Find distance between point A & point 1,2,3.
Find distance between point B & point 1,2,3.
Find distance between point C & point 1,2,3.
I need this distance in C# code, currently my implementation is as below
Javascript that makes call to Google Map API resides in aspx.
I call this javascript from c# using below code
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(this.GetType(), "ValError", "testDistance(lat1,long1,lat2,long2)", true);
My testDistance() method is written in javascript and gives me correct road distance.
Problem:
Getting the distance back in server side.
I am using hidden variable to save distance and get it back in server side but the issue is, that call to calculate distance has to be executed in a for loop in c# since there are various distances to be calculated and saved.
But i am unable to do so as hidden variable is set only at the first call and rest all distance values that are derived in subsequent calls are lost.
in javascript once i get distance i save it to hidden value like below.
var hiddist= document.getElementById("hidDistance");
hiddist.value=hiddist.value+distance;
Please help & suggest how can this be done?

I know your struggles with this one. I always use a jquery ajax post to call a webservice that I have in my C# project to pass data back to the codebehind from the clientside. Please view this webpage this shows a good example of how to do this, but there are probably hundreds. From what I have seen this is probably one of the better ways to handle this situation, this is also how I do all of my google maps pages that I create.
http://dotnetguts.blogspot.com/2012/01/jquery-ajax-examples-by-calling-aspnet.html
One other thing I would note is that I usually create classes in my codebehind and then join them all together. (aka a class of multiple classes, maybe one class is a list of a class) Then when I pass them to the client side via something like. :
return parentClass.toArray();
Doing the above really allows you to handle/pass a lot more data in between the client and codebehind and also do so in a lot more uniform manner rather than passing around a string of a billion variables. (One side note you can actually pass too much data between the client and codebehind doing it this way, which I have run into, but I wouldn't worry about that now) HTH

Related

How to scrape data on a web site that is changing contents in active manner?

I would like to grab satellite positions from the page(s) below, but I'm not sure if scraping is appropriate because the page appears to be updating itself every second using some internal code (it keeps updating after I disconnect from the internet). Background information can be found in my question at Space Stackexchange: A nicer way to download the positions of the Orbcomm-2 satellites.
I need a "snapshot" of four items simultaneously:
UTC time
latitude
longitude
altitude
Right now I use screen shots and manual typing. Since these values are being updated by the page - is conventional web-scraping going to work here? I found a "screen-scraping" tag, should I try to learn about that instead?
I'm looking for the simplest solution to get those four values, I wonder if I can just use urllib or urllib2 and avoid installing something new?
example page: http://www.satview.org/?sat_id=41186U I need to do 41179U through 41189U (the eleven Orbcomm-2 satellites that SpaceX just put in orbit)
Those values are calculated with a little math using javascript. The calculations are detailed here: https://www.satview.org/track.js
So, I guess one option is to write that script (plus any dependencies) in the language of your choice and use it to return your desired values.
There is one major function track() which takes arg $modo which can be one of two values - tic or plot.
There may be other source files (dependencies) referenced:
The easier way would probably be to use something which allows javascript to run e.g. automating a browser, and extracting the calculated values as they are generated.

How do I load data from a record into multiple edittexts in android studio?

I'm currently working through my A Level computer science controlled assessment, and am making an application designed to help Scout Leaders manage their group. This is my first time working in Java, SQLite, Android Studio and XML so I've run into a few problems along the way. At this point in time, I'm in the process of creating a login system, part of which involves editing login details. I was wondering if there's a way of loading multiple values from one record into different EditTexts at once, so the user only needs to edit the already-existing username and password, rather than type it in again with a slight edit? Thanks in advance. I didn't think it necessary to include any code in this question, as I'm only looking for an example, however if it would help please don't hesitate to ask - I just couldn't find a guide on this anywhere else.
You retrieve the data into a Cursor via a query that selects the required columns.
You then move to the appropriate row (record) in the Cursor (probably the first and only row).
For each EditText you set the text, using the setText method with the data from the respective column using an appropriate get???? method passing the column offset to the method (e.g. your_cursor.getString(<the_column_offset>)).
Rather than calculating and hard coding an offset, it is more reliable and flexible to use the getColumnIndex(<the_column_name_as_string>) method.
After all have been set you then close the Cursor
Note and would be replaced with respective values specific to the App.

Find nearest locations from json Sencha Touch 2

I'm trying to setup a portion to my app where the user's mobile location (which I have working) is used to find the nearest locations (lets say within 15 miles) against a json store of locations (lets say of 40 or so and it will increase).
I've been racking my brain how to go about this. I believe Distance Matrix (looking at the Google API, but no idea how to implement it from the docs) is something I need, but I can't figure how to load the json list and use it against the location (still a n00b).
If there's a tutorial or some details on how to go about it would be great. I just need a point in the right direction.
Any info is great, thanks ahead of time.
I'm using Sencha Touch 2.0.1, a json store and using the Google Maps JavaScript API v3.
Matt
You'd be better off doing that processing on the backend and sending only the close records back to the client. This will keep your client app from getting bogged down.
You can use Postgresql/Postgis for this if you store the lat/long points as spatial data. You can also do this with the MySQL spatial extensions. If you want to build the haversine formula into a MySQL function, you can draw 15 mile radii around all of your points and use MySQL's builtin 'within' function. If you'd rather use a flavor of NoSQL, then CouchDB has a nice GeoCouch extension which can perform the function you desire.
Yea, figured out a way. More than likely not the best, but it'll work for now.
I'm loading all the latitudes and longitudes with the locations into the store file.
Then, on initialize, it takes the current location and matches it against the stored locations and runs the Haversine formula with each one. Once it has all of the distances, it sorts and done.

Working with google maps api

I am trying to build a map based query interface for my website and I am having difficulty finding a starting point besides http://developer.google.com. I assume this is a rather simple task but I feel as though I am on a wild goose chase. Anyway the problem is the existing site places people into a category based on their address (primarily the zip code), this is not working out because of odd shapes and user density so I would like to solve the problem by creating custom zones.
I am not looking for a proprietary solution because I would really like to accomplish this on my own, I just need some better places to start or better suggestions for searches.
I understand that I will need to create a map with my predetermined polygons.
I understand how to create a map with polygons via js.
I do not understand how data will request which zone it is within and how it will return it as a hash I can store. eg. user=>####, zone=>####, section=>#####
http://blog.appdelegateinc.com./point-in-polygon-checking-with-google-maps.html
has some JS you can add to give the ability to test whether a point is within a polygon (sample: http://blog.appdelegateinc.com./static/samples/point_in_polygon.html ) using this approach: http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm
I think as you place the markers, you'll hold them in an array (of objects)...then loop through, doing some sort of reduction of which polygons to test, testing those that remain, if inPoly, set marker.zone and marker.section to whatever suits your needs

How to test two numbers that appear on different pages?

Have a stored procedure that produces a number--let's say 50, that is rendered as an anchor with the number as the text. When the user clicks the number, a popup opens and calls a different stored procedure and shows 50 rows in a html table. The 50 rows are the disaggregation of the number the user clicked. In summary, two different aspx pages and two different stored procedures that need to show the same amount, one amount is the aggregate and the other the disaggregation of the aggregate.
Question, how do I test this code so I know that if the numbers do not match, there is an error somewhere.
Note: This is a simplified example, in reality there are 100s of anchor tags on the page.
This kind of testing falls outside of the standard / code level testing paradigm. Here you are explicitly validating the data and it sounds like you need a utility to achieve this.
There are plenty of environments to do this and approaches you can take, but here's two possible candidates
SQL Management Studio : here you can generate a simply script that can run through the various combinations from the two stored procedures ensuring that the number and rows match up. This will involve some inventive T-SQL but nothing particular taxing. The main advantage of this approach is you'll have bare metal access to the data.
Unit Testing : as mentioned your problem is somewhat outside of the typical testing scenario where you would oridnarily Mock the data and test into your Business Logic. However, that doesn't mean you cannot write the tests (especially if you are doing any Dataset manipulation prior to this processing. Check out this link and this one for various approaches (note: if you're using VS2008 or above, you get the Testing Projects built in from the Professional Version up).
In order to test what happens when the numbers do not match, I would simply change (temporary) one of the stored procedure to return the correct amount +1, or always return zero, etc.

Resources