How to display lines created in android in web google maps? - android

Does anyone know how to display points, lines etc. (basically every overlay) created in android in standard google maps on website? The android db is synchronized with remote db. I'm getting the points from the database, creating kml file from them and uploading in to the map. The problem is that the areas I've created are not appearing where they should. They're somewhere on the ocean. I thought that's because I'm running this code in android:
Double lat = location.getLatitude()*1E6;
Double lng = location.getLongitude()*1E6;
So basically I'm doing microdegrees here. I thought that dividing lat and long from db by 1E6 would do the trick but it didn't. Can someone please help me on that one? Thanks in advance.

I don't know which format is expected by the map.
If it is normal coordinates, then I guess you would need to do:
float lat = ((float)location.getLatitude()) / 1E6;
Otherwise, if it is expecting it in int format, you don't need to do anything
P.S. Assuming getLatitude() returns an int, the cast to float is important. Otherwise 4539845 will become 45 and not 45.39845

I agree with ltsik, the E6 format is basically the regular latitude multitplied by 1E6 (or 1,000,000 whichever one you prefer) so it makes perfect sense that the variables lat and lng are obtained by dividing and not multiplying

Related

Find elements within 5km of a given longitude/latitude

I am creating an app that has a features that needs to find supermarkets that are in a 5km range from the user.
I thought that using longitude and latitude would be a good idea (I should store those two values as atributes on a supermarket table and I'd be ready to go).
Once I created my table and inserted it's values, I went to look for a solution on how could I get those supermarkets from my database.
What I had in mind would be a select with a not so complex WHERE clause that would solve all my problems. Instead, I found a bunch of different ways of doing it:
1) Create an square around the user location, find the supermarkets that are inside of it and then find the ones that are actually in that range
2) Create extra coluns on your table
3) Use the cosine law
4) Find out how to convert latitude/longitude to kilometers and use Pythagorean Theorem (for ranges that are not so wide)
The three problems are that any solution is made on the database (with a where clause), I have no idea which one has more performance or is better in any aspect and it's not like I'm getting how to use those exemples. So... What should I use remembering that I have and SQLite database and android?
Thanks :)
ADDING MORE INFORMATION:
The first problem was to know which one I should use.
The problem I had with this one was the this:
My user location is:
longitude = -22.82753105;
latitude = -47.03398022;
My where statement
WHERE latitude < -47.078946300295925 AND
latitude > -46.989014139704054 AND
longitude > -22.76155626735494 AND
longitude < -22.89350583264506
I have a market on my database which location is the same the user and I do get a list with this very element once I select the ones that are in the square, but when I iterate on my list, it removes my element from the list bacause the if return FALSE.
if (getDistanceBetweenTwoPoints(mercado, userLocation) <= RANGE)
On the getDistanceBetweenTwoPoints, if I debug it, I get:
dLat = -0.4224822382331485
dLon = 0.4224822382331485
lat1 = -0.39841557692373836
lat2 = -0.8208978151568869
a = 0.07157979929009457
c = 0.5416864422451098
d = 3451084.323543594
And since the if compares "d" with range, it's like this:
if(3451084.323543594 <= 5000) { //my range is 5km
// keep element
else
// remove it from list
Does anyone can tell me what is the problem??

GeoPoint Creation in android

GeoPoint point = new GeoPoint(
(int) (userlocation.getLatitude() * 1E6),
(int) (userlocation.getLongitude() * 1E6));
I am creating geo point like above
but it's not at exact location of user
it's nearly 500 to 600 meters away
Here userlocation is location I am getting from location listener
In user location I get values something like
18.453225455645 & 78.15446456546
But while plotting I can use only
18.453225 & 78.154464
i.e. -- only six digit after decimal. if I try to use extra values marker shows wrong location.(It's due to geopoint needs values in int )
How I can plot exact location on map??
Edited:-- I don't think any one has solution on this. I checked few apps & find out one app called myTaxi which has more accuracy than Google map don't know how they get that. Currently I am just rounding latitude & longitude.
Thank You
a. Just by removing the last few digit after six digits will not give you an error of 500-600 m as 5 digit after decimal places should give you precision of about 1m.
b. Are you using GPS or some other location provider? Use only GPS as Location Provider if you want accurate location. There is a catch though GPS would require a line-of-sight to work correctly.

Android google-maps longitude/latitude calculation question

I have seen it pretty often so far that for some reason the latitude or longitude values return by getLatitude() are multiplicated with 1E6 in Google-Maps-examples. What's the reason for this? Why 1E6? What's wrong with the raw values returned by those functions ?
I think I've read somewhere that this is related to performance. getLatitute() returns a double which is floating-point datatype. Math on floating point datatypes is slow if the device doesn't support floating-point operations.
So by multiplying the double value with 1E6, degrees become microdegree and so the calculation can be done with integer math without loosing too much resolution.
Its not just Google maps, I work with some maritime chart APIs on Windows PCs & they use a mixture on decimal degrees & 1E7 degrees. It just seems to be the functions were written that way & no one is bothered to unify them all.
The reason they are multiplied by 1E6 is because the GeoPoint class (which is used to plot points on a Google Map) uses microdegree latitude and longitude as integers. Multiplying by 1E6 converts degrees into microdegrees. The reason Google chose to do it this way is up to debate, but it probably has to do with the fact that the Google Maps themselves are not extremely accurate, and using a raw double value to 10 or more decimal places returned by the GPS is an unnecessary level of accuracy to plot a point on a Google Map.

convert wgs 84 to lat/long

Hi
I am having a little trouble figuring out how to convert between types of coordinates. I have a list of coordinate sets with the following description
"Coordinates are always in the WGS84 system. All coordinates a represented as integer
values x and y where the coordinate value is multiplied with 1,000,000."
An example:
559262 6319512
Well, I need to convert these to long/lat (and back) so i can use these in google maps (android). But this is not as easy as it seams. I have been searching around and did find some code to do this, but it does not seam to work properly. Anyone who can provide some code for doing this? If possible, I would like to avoid a big geo framework (it has to be used in an android application).
thanks.
best regards, kenneth
EDIT:
I did find a solution on my own. I downloaded the class described here:
http://www.ibm.com/developerworks/java/library/j-coordconvert/
And it works fine. Hope someone can find it useful.
I am sorry for posting before having done my homework decently. Thanks to everyone who posted
If you're getting the location from the GPS on android, you will get a Location object that holds Lat/Long as doubles. In order to display a point on Google Maps, you need to turn these double values into a GeoPoint object using:
GeoPoint location = new GeoPoint(
(int) (mLocation.getLatitude()) * 1E6),
(int) (mLocation.getLongitude()) * 1E6)
);
Hope thats helpful.
All GPS systems give their latitude and longitude with respect to the WGS84 model of the Earth. Unless you intend to give the lat/lon with respect to a nation's local model, such as the British OSGB36 model, you should be fine treating the coordinates you have as representing microdegrees. Even here in the Britain, the Admiralty now print their nautical charts with lat/lon relative to WGS84, I expect the Ordnance Survey land maps will follow suit soon, if they haven't already done so.

Get Lat and Long, Android

I need lat and lng of a point on a google map. It has to look like that
8.53171539306641 for example
but when I go to maps.google.com I get just
8.532493
There is a possibility to receive lat and lng that have such a length 8.53171539306641 but I do not remember how
I am sure you would have looked into this: Try receiving the value in a double precision data type.
If this doesn't solve it, could you please paste some code for us to get a good sense of what exactly you are trying to achieve.

Categories

Resources