×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Problems with Google Maps API in Java ME

    Hi there,

    I'm making an application witch uses the Google Maps static api, i used the code example from the article:
    Google Maps API in Java ME

    My problem is that i have a list of waypoints in the format (lat,lng) and i need the get the position of the points on the static map in pixels... I tried to convert the code from the page that the article also links to(http://home.provide.net/~bratliff/adjust.js) but it dosn't work when i need to lat/lng to x/y...

    here's my code that should do the same at adjust.js:


    Code:
    public static GPSPoint XYtoLL(GPSPoint mapCenter, int deltaX, int deltaY, int zoom){
        	return new GPSPoint(
        			YToL(LToY(mapCenter.getLat()) + (deltaY<<(21-zoom))), 
        			XToL(LToX(mapCenter.getLng()) + (deltaX<<(21-zoom)))
        			);
        	
        }
        
        public static Point LLtoXY(GPSPoint mapCenter, GPSPoint point, int zoom){
        	return new Point(
        			(int)round(Double.doubleToLongBits((LToX(point.getLng())-LToX(mapCenter.getLng()))) >> (21-zoom)),
        			(int)round(Double.doubleToLongBits((LToY(point.getLat())-LToY(mapCenter.getLat())))>>(21-zoom))
        	);
        }
    
    static double LToX(double x)
        {
        	return round(offset + radius * x * Math.PI / 180);
        }
         
        static double LToY(double y)
        {
        	return round(
        		offset - radius * 
        		Double.longBitsToDouble(MicroDouble.log(
        			Double.doubleToLongBits(
        			(1 + Math.sin(y * Math.PI / 180))
        			/
        			(1 - Math.sin(y * Math.PI / 180))
        			)
        		)) / 2);
        }
         
        static double XToL(double x)
        {
        	return ((round(x) - offset) / radius) * 180 / Math.PI;
        }
         
        static double YToL(double y)
        {
        	return (Math.PI / 2 - 2 * Double.longBitsToDouble(
        				MicroDouble.atan(
        					MicroDouble.exp(Double.doubleToLongBits((round(y)-offset)/radius))
        				)
        			)) * 180 / Math.PI;
        }
        static double round(double num)
        {
        	double floor = Math.floor(num);
         
        	if(num - floor >= 0.5)
        		return Math.ceil(num);
        	else
        		return floor;
        }
    GPSPoint consists of two doubles... (lat and lng)

    the XYtoLL works perfekt... but the LLtoXY doesn't...

    here's two results og the LLtoXY:

    1. input LL: (57.69255211496328 | 10.51119089126587) out xy-2147483349,-2147483383)
    2. input LL: (57.54546006577498 | 10.32991647720337) out xy-2147483349,-2147483383)

    Can anyone tell me what I'm doing Wrong?

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Problems with Google Maps API in Java ME

    I don't see a LLtoXY method...

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Re: Problems with Google Maps API in Java ME

    Tiger79: It's the second method:

    and here it is again:
    Code:
    public static Point LLtoXY(GPSPoint mapCenter, GPSPoint point, int zoom){
        	return new Point(
        			(int)round(Double.doubleToLongBits((LToX(point.getLng())-LToX(mapCenter.getLng()))) >> (21-zoom)),
        			(int)round(Double.doubleToLongBits((LToY(point.getLat())-LToY(mapCenter.getLat())))>>(21-zoom))
        	);
        }

  4. #4
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Problems with Google Maps API in Java ME

    have you tried single-stepping through the code with a calculator by hand and check where the calculations go wrong ?
    you do know what is getting calculated exactly ? Or did you just copy-paste the code without knowing why specific calculations are done ?
    ANyways, single-stepping and looking at the value of every variable would seem the most logical thing to me...

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Re: Problems with Google Maps API in Java ME

    Well,

    my problem is that i don't know the defenition og the gMaps zoom level, and therefor doesn't understandt that part of the calculation... i think the problem lies with the zoom level...

Similar Threads

  1. Google Maps API - Map download does not work
    By snowisfree in forum Mobile Java General
    Replies: 4
    Last Post: 2009-03-12, 12:10
  2. Google Maps using Location Api
    By Burim in forum Symbian
    Replies: 1
    Last Post: 2008-08-10, 18:32
  3. Google Maps API to Symbian
    By Olaris in forum Symbian
    Replies: 1
    Last Post: 2007-06-18, 18:30
  4. NCPT Java API docs missing?
    By janne_l in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2004-08-19, 14:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •