Finding Latitude and Longitude around a known latitude and longitude if distance is known - latitude-longitude

Please check the code which i tried to write with the help of the link suggested by people below. Please tell whether i have implemented the logic correctly or not. I have pasted the data in excel sheet to see its plot on http://www.copypastemap.com/map.php
`
import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class FindingLatLongAlongACircle {
static double latitude= 35.306614;
static double longitude= -80.7444093;
//static double circumofEarth= 40075000;
static double R=20;
public static void main(String[] args) throws IOException {
File f= new File("C:\\Users\\Manu Chaudhary\\Desktop\\LatongAroundaPoint.xls");
WritableWorkbook myexcel= Workbook.createWorkbook(f);
WritableSheet mysheet= myexcel.createSheet("mysheet",0);
int YAxis1=0;
int YAxis2=0;
// Added now
jxl.write.Label k1;
jxl.write.Label k2;
double angle=0;
double angleRadian=0;
// double changeInLat;
//double changeInLong;
double dx;
double dy;
double final_latitude=0;
double final_longitude=0;
double delta_longitude;
double delta_latitude;
while(angle<360){
angle=angle+15;
angleRadian= Math.toRadians(angle);
dx= R* Math.sin(angleRadian);
dy= R* Math.cos(angleRadian);
//changeInLat= (distance* Math.cos(angleRadian))/(circumofEarth* Math.cos(lat1));
//changeInLong= (distance*Math.sin(angleRadian))/circumofEarth;
//newLatitude= lat1+changeInLat;
//newLongitude=long1+ changeInLong;
delta_longitude= dx/(111320* Math.cos(latitude));
delta_latitude= dy/110540;
final_latitude= latitude+ delta_latitude;
final_longitude=longitude+ delta_longitude;
YAxis1++;
YAxis2++;
k1= new jxl.write.Label(0,YAxis1,Double.toString(final_latitude));
k2= new jxl.write.Label(1,YAxis2,Double.toString(final_longitude));
try {
mysheet.addCell(k1);
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mysheet.addCell(k2);
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("The value of latitude at "+ angle + " angle is"+ final_latitude);
System.out.println("The value of longitude at "+ angle + " angle is"+ final_longitude);
}
myexcel.write();
try {
myexcel.close();
} catch (WriteException e) {
e.printStackTrace();
System.out.println("Finish");
}
}
}
`Suppose i know the latitude and longitude of a point. Can i calculate the latitude and longitude all around the point(approx. 16 points) if i know the distance of separation? I searched the stackoverflow and found two useful links.
Calculate second point knowing the starting point and distance
Google Maps V3 Circle & Circle that I created do not match
For making the question clear please see the Latitudes and longitudes required. Please help me with a code in python.

This is just basic trig:
θ = angle of elevation in a triangle formed by connecting an outer dot to the center dot, then extending a 90º line horizontally from the center dot until an altitude can connect the two priorly drawn lines
ec = earth's circumference
distance•cos(θ)/(ec•cos(latitude)) = Δlong
distance•sin(θ)/ec = Δlat
Please attempt some code, this site isn't to have people do your homework.

Related

JOptionPane cannot find symbol in module

So, the assignment for this week was all about modularization, and the code must contain 6 modules, which is why it looks like a complete mess. Anyway, I'm getting an error that says the module cannot find JOptionPane even though I declared it for the main method. I've posed the code below. Any help appreciated.
Specifically, I'm getting it right here, with this line of code posted at the top.
{ public static String getItemShape ()
{
String typeOfShape;
typeOfShape = JOptionpPane.showInputDialog("Please enter 'C' for a Circle, or 'S' for a Sphere"); //getting input for shape
return typeOfShape; //returning to method
}
}
//This program will find the area or volume of a circle or sphere,
respectively.
import javax.swing.JOptionPane;
public class Java_Chapter_9
{
public static void main(String args[])
{
//Declarations
String itemShape; //type of shape
String runProgram; //user control
Double itemRadius; //radius of tem
Double finalAnswer; //calculation for final answer
//End Declarations
showGreeting (); //Call greeting module
runProgram = JOptionPane.showInputDialog("Please enter 'Y' to run the
program, or 'N' to quit"); //giving user control
while (runProgram.equalsIgnoreCase("y")) //loop for continuous use
{
itemShape = getItemShape (); //calling itemShape module
itemRadius = getItemRadius (); //calling itemradius module
finalAnswer = calculateAnswer (itemRadius, itemShape); //calling the
module for calculation with paramaters
runProgram = JOptionPane.showInputDialog("Enter 'Y' to input more, or
'N' to Quit");
}
showGoodbye ();
}
////////////////////////////////////////////////// starting modules
public static void showGreeting () //greeting module
{
System.out.println("Welcome to the program");
System.out.println("This program will show you the area or volume of a
shape");
}
///////////////////////////////////////////////// seperating modules
public static String getItemShape ()
{
String typeOfShape;
typeOfShape = JOptionpPane.showInputDialog("Please enter 'C' for a
Circle, or 'S' for a Sphere"); //getting input for shape
return typeOfShape; //returning to method
}
////////////////////////////////////////////////// seperating modules
public static double getItemRadius ()
{
double radiusOfItem; //variable withing scope of module
String radiusofItemInput;
radiusOfItemInput = JOptionPane.showInputDialog("Please enter the
radius of the item in inches: ");
radiusOfItem = Double.parseDouble(radiusofItemInput);
return radiusOfItem;
}
////////////////////////////////////////////////// seperating modules
public static double calculateAnswer (double itemRadius, string itemShape);
{
double circleArea;
if (itemShape.equalsIgnoreCase("c"))
{
circleArea = 3.14159 * (itemRadius * itemRadius);
system.out.print("The area of the circle in inches is " + circleArea);
return circleArea;
}
else
{
calculateAnswerSphere (itemRadius, itemShape);
}
/////////////////////////////////////////////// seperating method
{
double sphereVolume;
sphereVolume = (4.0/3) * 3.14159 * (itemRadius * itemRadius *
itemRadius);
system.out.print("The volume of the sphere in cubic inches is "
+sphereVolume);
}
end If;
}
public static void showGoodbye ()
{
System.out.println("Thank you for using the program. Goodbye.");
}
}
Anyway, I'm getting an error that says the module cannot find
JOptionPane even though I declared it for the main method
You have a typo in this line
typeOfShape = JOptionpPane.showInputDialog("Please enter 'C' for a Circle, or 'S' for a Sphere"); //getting input for shape
It should be JOptionPane instead of JOptionpPane. Remove the p

Real time GPS UWP

I really want to know how do I can update the position of the user in the map while the UWP app was running in bakground
Here is my code right now
private async void PinPoints()
{
//Pin point to the map
Windows.Devices.Geolocation.Geopoint position = await Library.Position();
double lat = position.Position.Latitude;
double lon = position.Position.Longitude;
//Geoposition alttest = await Library.Temp();
//alt = alttest.Coordinate.Altitude;
DependencyObject marker = Library.Marker(""
//+ Environment.NewLine + "Altitude " + alt
);
Display.Children.Add(marker);
Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation(marker, position);
Windows.UI.Xaml.Controls.Maps.MapControl.SetNormalizedAnchorPoint(marker, new Point(0.5, 0.5));
Display.LandmarksVisible = true;
Display.ZoomLevel = 16;
Display.Center = position;
}
This function will pinpoint the current location for me but it will do only when user open this page due to I've put it in the public Map() {}
Current : Get the location when open map page and when I walk the map still be the same place
What I want : The position keep changing while I move on and also run on background (If application is close location data still changed)
Is there any code to solve this location problem if I have to add code where should I fix and what should I do?
Additional now I perform the background (Not sure is it work or not) by create the Window Runtime Component (Universal) with class like this
*I already put this project as the reference of the main one
namespace BackgroundRunning
{
public sealed class TaskBG : IBackgroundTask
{
BackgroundTaskDeferral _deferral = null;
Accelerometer _accelerometer = null;
Geolocator _locator = new Geolocator();
public void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
try
{
// force gps quality readings
_locator.DesiredAccuracy = PositionAccuracy.High;
taskInstance.Canceled += taskInstance_Canceled;
_accelerometer = Windows.Devices.Sensors.Accelerometer.GetDefault();
_accelerometer.ReportInterval = _accelerometer.MinimumReportInterval > 5000 ? _accelerometer.MinimumReportInterval : 5000;
_accelerometer.ReadingChanged += accelerometer_ReadingChanged;
}
catch (Exception ex)
{
// Add your chosen analytics here
System.Diagnostics.Debug.WriteLine(ex);
}
}
void taskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
_deferral.Complete();
}
async void accelerometer_ReadingChanged(Windows.Devices.Sensors.Accelerometer sender, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs args)
{
try
{
if (_locator.LocationStatus != PositionStatus.Disabled)
{
try
{
Geoposition pos = await _locator.GetGeopositionAsync();
}
catch (Exception ex)
{
if (ex.HResult != unchecked((int)0x800705b4))
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
public void Dispose()
{
if (_accelerometer != null)
{
_accelerometer.ReadingChanged -= accelerometer_ReadingChanged;
_accelerometer.ReportInterval = 0;
}
}
}
}
Your Solution :
Make 3 projects in your solution.
1> Background Task "references App_Code"
2> App_Code "contains calculations,mostly Backend Code"
3> Map(Main Project) "references App_Code"
Register a background Task to your project and specify the time interval after which it should run again
Scenario 1> App Open,User Requests Update
Trigger Your background Task from code behind.
Scenario 2> App Closed,Not Being Used
Run your background task!
So basically keep your backgroundTask simple(make it a class in whose run method you just call the proper App_Code Classes Method) and all calculations that you want to happen in the background keep them in App_Code. Also, if I am no wrong the minimum interval between which a background Task is triggered by itself cannot be set below 15 minutes.
For real-time you could look at SignalR ( can't help any further here)

Oscilloscope app using mpandroidchart

I'm trying to create an app that can display linegraphs at a sample rate of 15 kHz frequency and have run into two main problems:
I cant seem to set the sample rate to anywhere below 1 ms(I'm using thread.sleep(1) to set the time duration between each value.
Also the graph shows too little onscreen at any given time. I've set xAxis.setSpaceBetweenLabels to 1 and still am only getting about 6 entries on screen at any given time. Is it at all possible to get a higher sample rate(at the order of nanoseconds) and get the chart to display much higher number of entries on screen?
Currently the app displays random values as the entries. This is the code snippet:
#Override
protected void onResume() {
super.onResume();
//real time addition
new Thread(new Runnable() {
#Override
public void run() {
//adding 100 entries
for ( int i = 0;i<3000; i++) {
runOnUiThread(new Runnable() {
#Override
public void run() {
addEntry();
}
});
//pausing between each addition
//pausing between each addition
try{
Thread.sleep(600);
} catch (InterruptedException e) {
// to manage error....
}
}
}
}).start();
}
EDIT: Figured out how to show more entries onscreen (setVisibleXRange) but still have the problem of increasing samplerate.
In order to increase sampling rate just use TimeUnit.NANOSECONDS.sleep instead of Thread.sleep.
Also don't forget to import TimeUnit library(alt enter doesnt work) ;)
Thanks for all the help.

Problems with KeyListener and JOGL

I'm trying to bind a key to translate a GL_QUAD around the screen. I created a class, as I will attach below, that implements KeyListener, and within that I have a method that upon the keypress of 'd', adds 0.1 to the x coordinates of the quad vertices. Now, I have two questions relating to this.
Firstly, it doesn't seem to do anything. Upon the keypress, nothing happens to the object.
Is there a better way to achieve what I am trying to do? My end goal is to eventually end up with a sprite, that the camera is focused upon, that can move around a visually 2D game world.
Thanks for your time.
Code:
SpriteTest.java
package com.mangostudios.spritetest;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.FPSAnimator;
public class SpriteTest
{
public static void main(String[] args) {
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
GLCanvas canvas = new GLCanvas(caps);
Frame frame = new Frame("AWT Window Test");
frame.setSize(300, 300);
frame.add(canvas);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
canvas.addGLEventListener(new Renderer());
FPSAnimator animator = new FPSAnimator(canvas, 60);
//animator.add(canvas);
animator.start();
}
}
Renderer.java
package com.mangostudios.spritetest;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
public class Renderer implements GLEventListener {
InputListener input = new InputListener();
#Override
public void display(GLAutoDrawable drawable) {
update();
render(drawable);
}
#Override
public void dispose(GLAutoDrawable drawable) {
}
#Override
public void init(GLAutoDrawable drawable) {
}
#Override
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
}
private void update() {
}
private void render(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
// draw a triangle filling the window
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f( input.xTran, 0.1f);
gl.glVertex2f( input.xTran,-0.1f);
gl.glVertex2f( -input.xTran, -0.1f);
gl.glVertex2f( -input.xTran, 0.1f);
gl.glEnd();
}
}
InputListener.java
package com.mangostudios.spritetest;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
public class InputListener implements KeyListener{
boolean loopBool = false;
float xTran = 0.1f;
float yTran = 0.1f;
#Override
public void keyPressed(KeyEvent d) {
loopBool = true;
while (loopBool = true) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
#Override
public void keyReleased(KeyEvent d) {
}
}
At first, you never call addKeyListener(). Secondly, you shouldn't put an infinite loop into keyPressed(). Thirdly, you use a NEWT KeyListener whereas you use an AWT GLCanvas :s Rather use GLWindow with a NEWT KeyListener or use an AWT GLCanvas with an AWT KeyListener or use NewtCanvasAWT. Finally, before writing your own example, try mine on Wikipedia in order to understand why it works.

Robotium test case not Running at all

Am a day old to Robotium. Hence trying to run some apps on Robotium.
I have done a simple calci app and am trying to run it using Robotium.
But the Robotium app is not responding at all. Neither the tests are being done.
I have included the permissions in Manifest file and all. But still the Program never runs.
My Source Code for Robotium Test is like this:
package com.example.demo.project.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;
import android.widget.TextView;
import com.example.demo.project.MainActivity;
import com.example.demo.project.R;
import com.jayway.android.robotium.solo.Solo;
public class SampleQA extends ActivityInstrumentationTestCase2<MainActivity> {
public SampleQA(Class<MainActivity> activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
private Solo solo;
/*public TestMain()
{
super(MainActivity.class);
}*/
#Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
public void testDisplayBlackBox() {
//Enter 10 in first edit-field
solo.enterText(0, "10");
//Enter 20 in first edit-field
solo.enterText(1, "20");
//Click on Multiply button
solo.clickOnButton("Multiply");
//Verify that resultant of 10 x 20
assertTrue(solo.searchText("200"));
}
public void testDisplayWhiteBox() {
//Defining our own values to multiply
float firstNumber = 10;
float secondNumber = 20;
float resutl = firstNumber * secondNumber ;
//Access First value (edit-filed) and putting firstNumber value in it
EditText FirsteditText = (EditText) solo.getView(R.id.EditText01);
solo.enterText(FirsteditText, String.valueOf(firstNumber));
//Access Second value (edit-filed) and putting SecondNumber value in it
EditText SecondeditText = (EditText) solo.getView(R.id.EditText02);
solo.enterText(SecondeditText, String.valueOf(secondNumber));
//Click on Multiply button
solo.clickOnButton("Multiply");
assertTrue(solo.searchText(String.valueOf(resutl)));
TextView outputField = (TextView) solo.getView(R.id.TextView01);
//Assert to verify result with visible value
assertEquals(String.valueOf(resutl), outputField.getText().toString());
}
#Override
protected void tearDown() throws Exception{
try {
solo.finalize();
}
catch (Throwable e)
{
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}
The Test is not getting executed at all.
Please help me out Folks!!
Thanks.
Can you be more specific on the errors that you are encounter? maybe put some examples?
Your main activity of the application under test it is named MainActivity?
Maybe you should change the constructor from
public SampleQA(Class<MainActivity> activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
to
public SampleQA() {
super(MainActivity.class);
}