[Not Solved] Making Libgdx Camera Synchron With google maps

Anything libgdx related goes here!

[Not Solved] Making Libgdx Camera Synchron With google maps

Postby GDXLIB » Tue Feb 21, 2017 5:18 pm

Hey there!

I want to make the libgdx camera synchron with the GoogleMaps camera. So when the googlemaps camera moves, the libgdx one should move in the same direction. That would allow sprites to look like they are actually on the map. Its some kind of simulation. Heres a picture of what i mean .

Lets say, i set the position of one sprite to the island of madagaskar :

beofre.PNG
beofre.PNG (234.28 KiB) Viewed 866 times


After i move the map, the libgdx camera should be moved too, but my current problem, instead that the sprite is still on top of madagaskar, its on the same screen location as before.

after.PNG
after.PNG (351.33 KiB) Viewed 866 times


So i want to achieve, that the libgdx cam is synchron with the maps cam. Then this iusse would be gone.


But any ideas how to do that ?


My first try, was to get the GoogleMaps-CameraPosition then convert it into pixel and after that reset the position of the libgdx camera. But that causes an weierd camera behavior, sometimes the camera moves quickly, other times in the whole wrong direction and sometimes it just wont move at all.

So thanks for your help and your time !:)
GDXLIB
 
Posts: 76
Joined: Sun May 08, 2016 3:48 pm

Re: [Not Solved] Making Libgdx Camera Synchron With google m

Postby GDXLIB » Wed Feb 22, 2017 1:32 pm

Yesterday i tried to improve my system a bit. But its still not working. It only acts more weierd.

First i found this method on the google developer sites. That should be used to calculate the pixel coordinates, even when they are out of the screen.

Code: Select all
 public Point project(LatLng latLng) {

        double siny = Math.sin(latLng.latitude * Math.PI / 180);

        siny = Math.min(Math.max(siny, -0.9999), 0.9999);

        return new Point(
                (int)(256 * (0.5 + latLng.latitude / 360)),
                (int)(256 * (0.5 - Math.log((1 + siny) / (1 - siny)) / (4 * Math.PI))));
    }


Then im calculating the camera position in pixel like this :

Code: Select all
               // cameraCoordinates = new Vector2((float)Math.floor(project(cameraPosition.target).x * cameraPosition.zoom), (float)Math.floor(project(cameraPosition.target).y * cameraPosition.zoom));
                Vector2 cameraCoordinates = new Vector2((float)Math.floor(project(map.getCameraPosition().target).x * map.getCameraPosition().zoom), (float)Math.floor(project(map.getCameraPosition().target).y * map.getCameraPosition().zoom));

                game.newLocation(cameraCoordinates);


But somehow that doesnt work. When i calculate the postion, and set the Libgdx camera to the pixel position of the Googlemaps camera, it acts very weierd. When i move the screen, the Maps Camera moves aswell, the position are send to the libgdx cam, which only moves sometimes and if it moves, than very strange. It looks like it just doesnt work.

Any other ideas ?
GDXLIB
 
Posts: 76
Joined: Sun May 08, 2016 3:48 pm

Re: [Not Solved] Making Libgdx Camera Synchron With google m

Postby GDXLIB » Thu Feb 23, 2017 9:40 am

Push
GDXLIB
 
Posts: 76
Joined: Sun May 08, 2016 3:48 pm

Re: [Not Solved] Making Libgdx Camera Synchron With google m

Postby Guich » Wed Jun 12, 2019 7:13 am

HI, did you fix the issue?
Guich
 
Posts: 82
Joined: Sun Dec 11, 2016 9:36 am

Re: [Not Solved] Making Libgdx Camera Synchron With google m

Postby shatterblast » Wed Jun 12, 2019 6:44 pm

Guich wrote:HI, did you fix the issue?

Since the other fellow had an issue, I suggest trying to send Google Maps stuff to a Frame Buffer Object first, and then, it should be safe to manipulate how you want. I think you can still use FBO stuff with SpriteBatch and similar.

https://github.com/mattdesl/lwjgl-basics/wiki/FrameBufferObjects
shatterblast
 
Posts: 306
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest