问题
My name is Cyrille and i'm working on a map app on codename one. The goal is to make an app that can search around the user for companies (with a search bar) and add companies they want to a list. Then the list appear in the main window and clicking on them show it on the map.
I've got a problem with the event part on codename one. Here's a part of my code :
PointLayer point = new PointLayer(new Coord(lat.doubleValue(), lng.doubleValue()),
companyName, null);
pl.addPoint(point);
pl.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
PointLayer p = (PointLayer) evt.getSource();
System.out.println("pressed " + p);
Dialog.show("Details", "" + p.getName() + "\nLatitude: " + p.getLatitude() + "\nLongitude: " + p.getLongitude(), "Ok", null);
}
});
Yes I took the basic map template ^^' My problem is : When i ask for the coordonates of point I get :
{'longitude':2.3485853, 'latitude':48.8769309}
but when I ask for the coordonates of evt.getSource i get :
{'longitude':261443.31964417442,'latitude':6254004.882818963}
which is kind of perturbing ...
I looked over the internet since yesterday but i didn't find any thing, maybe i'm not searching at the right place. Any clue of what's happening ?
EDIT : Thanks to the replyers i found the issue. The coordonates was given in an other system use by codename one : Popular Visualisation CRS Mercator. In order to use it you have to convert it with : com.codename1.maps.Mercator.inverseMercator(latitude, longitude); Or you can use google marker instead of codename one's [That's what i did]
回答1:
I think the coordinates you get in the event are in the Popular Visualisation CRS Mercator (EPSG:900913 or EPSG:3785) coordinate system, which is what the map control uses. The points you add in lat/lon are automatically transformed to this system when added to the map. "latitude" and "longitude" are slightly misleading; "x" and "y" are the standard terms for projected coordinates.
回答2:
I can't find why it returns this value but maybe you can bypass this issue by building a coord object.
Example :
Coord coord = new Coord(lat.doubleValue(), lng.doubleValue());
PointLayer point = new PointLayer(coord, companyName, null);
pl.addPoint(point);
pl.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
PointLayer p = (PointLayer) evt.getSource();
System.out.println("pressed " + p);
Dialog.show("Details", "" + p.getName() + "\nLatitude: " + coord.getLatitude() + "\nLongitude: " + coord.getLongitude(), "Ok", null);
}
});
EDITED I had the same problem 1 month ago. I resolved it by using the MapContainer and i use the addMarker(); from the map. By this way i can use it like this :
MapContainer map = new MapContainer(); // This used gMaps
for(Coord points : coords){
map.addMarker((EncodedImage) myIcon, coord,"","", new ActionListener(){
Dialog.show("Details", "" + p.getName() + "\nLatitude: " + points.getLatitude() + "\nLongitude: " + points.getLongitude(), "Ok", null);
})
}
来源:https://stackoverflow.com/questions/36329529/source-event-strange-latitude-longitude