Im trying to get my current latitude and longitude values using LocationManager in Codename One but the values i'm getting is for a different location.
Here is my code:
LocationManager locationManager = LocationManager.getLocationManager();
Location location = locationManager.getCurrentLocation();
Double loc1= location.getLatitude();
Double loc2= location.getLongitude();
System.out.println("Latitude: "+loc1);
System.out.println("Longitude: "+loc2);
Output:
Latitude: 40.715353
Longitude: -74.00497299999999
My correct current Latitude and Longitude values are 3.xxxx and 101.xxxx respectively.
Please how can I get these correct values from LocationManager?
That is default location on Simulator.
Note that you can't get your actual location on Simulator without entering it yourself.
To set your simulator to use your current location, Click Simulate on your simulator and select Location Simulation. Enter your LatLong values for Available and Click Update. The Google map will shift view to your location, So would your app.
You can keep Location Simulator open while you test your app.
On a side note, if your app needs a real time location I would suggest you use getCurrentLocationAsync(). Below is an example:
InfiniteProgress ip = new InfiniteProgress();
Dialog ipDlg = ip.showInifiniteBlocking();
Location location = LocationManager.getLocationManager().getCurrentLocationSync(30000);
ipDlg.dispose();
if (location == null) {
try {
location = LocationManager.getLocationManager().getCurrentLocation();
} catch (IOException err) {
Dialog.show("Location Error", "Unable to find your current location, please be sure that your GPS is turned on", "OK", null);
return;
}
}
Double loc1 = location.getLatitude();
Double loc2 = location.getLongitude();
Log.p("Latitude: " + loc1);
Log.p("Longitude: " + loc2);
Related
Im running this code and it's only saving the last element of the list. Each time it prints out I only get the price.
addThing(whichList){
let link = prompt("whats the link");
let item = prompt("whats name of the item");
let price = prompt("whats the price, only put in numbers otherwise will causes error")
let whyNoWork=[link,item,price]
price = parseInt(price);
//TODO have this line working console.log(this.state[whichList]);
this.setState({whichList:whyNoWork})
console.log(whyNoWork)
// https://stackoverflow.com/questions/29886552/why-are-objects-not-iterable-in-javascript look at this to add object into state
// okay I think to by pass I can just run it as a list:[(da link here),(name be here),(price)]
}
Note that works in a normal envoriment, but when i put this into a
I used to use fql to get latitude and longitude from Place.
How do I do it nowadays? I've got the user's location, but only id and name are filled in. Everything else is null. Code:
FacebookClient fc = new DefaultFacebookClient(token, Version.VERSION_2_9);
User user = fc.fetchObject("me", User.class, Parameter.with("location"));
Location loc = fc.fetchObject(user.getLocation().getId(), Location.class);
Also tried:
Place pl = fc.fetchObject(user.getLocation().getId(), Place.class);
Same thing.
As I wrote in the RestFB bugtracker:
FacebookClient fc = new DefaultFacebookClient(token, Version.VERSION_2_9);
User user = fc.fetchObject("me", User.class, Parameter.with("fields","location"));
Page pageOfUserLocation = fc.fetchObject(user.getLocation().getId(),
Page.class, Parameter.with("fields","location");
if (pageOfUserLocation.getLocation() != null) {
System.out.println("longitude: ", pageOfUserLocation.getLocation().getLongitude());
System.out.println("latitude: ", pageOfUserLocation.getLocation().getLatitude());
}
I'm trying the recover the location of a card previously set, so I could replace the HTML card with a map and a route with Glass last location.
But when I get the card back, it has no location. The location is set on card because I tested on Glass and it's all right.
Here's my piece of PHP code:
elseif ($user_action['type'] == 'CUSTOM' && $user_action['payload'] == 'show-in-map')
{
$timeline_item_id = $request['itemId'];
$timeline_item = $mirror_service->timeline->get($timeline_item_id);
$patch = new Google_TimelineItem();
$cardFomater = new Card_Formater($patch->getHtml());
$cardLocation = $timeline_item->getLocation();
$patch->setHtml($cardFomater->replaceHtmlWithMap($location->getLatitude(),$location->getLongitude(),
$cardLocation->getLatitude(),$cardLocation->getLongitude()));
$mirror_service->timeline->patch($timeline_item_id, $patch);
}
It says the $cardLocation does not have the property getLatitude().
Program crashes when set location coordinates using MKMapView.
Log:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:+112.57075000, +37.87049600 span:+0.05165163, +0.43945312>'
span in my program is
MKCoordinateSpan span;
span.latitudeDelta = .05;
span.longitudeDelta = .02;
after coding:
self.mMKMapview.region = [self.mMKMapview regionThatFits:region];
as the log shows, span changes to :+0.05165163, +0.43945312
anyone help please, I have been standstill here for two days.
Thanks!
The problem is the center coordinate:
+112.57075000, +37.87049600
The latitude must be from -90 to +90 so +112.57075 is out of range.
Check how the center coordinate is being set or maybe the data is backwards.
Also, you don't need to explicitly call regionThatFits because the map view does it automatically when you set the region normally (ie. just call setRegion). It's normal, by the way, for the map view to adjust the span as needed to fit the map view dimensions or zoom level.
I use the following code to set the region:
if( centerLat > -89 && centerLat < 89 && centerLng > -179 && centerLng < 179 ){
[self.mapView setRegion:region animated:YES];
}
I would rather suggest to use CLLocationCoordinate2DIsValid
so something like
guard CLLocationCoordinate2DIsValid(centerLat) else {
return
}
Is there an easy way to determine the maximum and minimum visible latitude and longitude in a VirtualEarth map?
Given that it's not a flat surface (VE uses Mercator projection it looks like) I can see the math getting fairly complicated, I figured somebody may know of a snippet to accomplish this.
Found it! VEMap.GetMapView() returns the bounding rectangle, even works for 3D mode as well (where the boundary is not even a rectangle).
var view = map.GetMapView();
latMin = view.BottomRightLatLong.Latitude;
lonMin = view.TopLeftLatLong.Longitude;
latMax = view.TopLeftLatLong.Latitude;
lonMax = view.BottomRightLatLong.Longitude;
Using the Virtual Earth Interactive SDK, you can see how to convert a pixel point to a LatLong object:
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
}
function DoPixelToLL(x, y)
{
var ll = map.PixelToLatLong(new VEPixel(x, y)).toString()
alert("The latitude,longitude of the pixel at (" + x + "," + y + ") is: " + ll)
}
Take a further look here: http://dev.live.com/virtualearth/sdk/ in the menu go to: Get map info --> Convert pixel to LatLong
To get the Max/Min visible LatLong's, you could call the DoPixelToLL method for each corner of the map.