Map API

Nutiteq Maps Lib SDK enables developing advanced mobile mapping applications.
Platforms: Android, RIM BlackBerry, Java ME (J2ME)
Download maps API SDK »
Untitled Document

Products

» View demos
» Downloads

Latest news

Last at Tue, 6 Dec 2011 18:37:53
Topic: New BlackBerry sample app
See more news »

Dragging a place marker on map

8 replies [Last post]
parthi2929
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 07/26/2009

Hi
I am trying to let user drag the place marker I have placed on map. Afaik there is no internal support in lib for this, so trying to implement with available methods. What I have been trying is to catch label clicked event and then in pointer drag event handling, I move place accordingly. The patch would be as follows:

public void elementClicked(OnMapElement arg0)
{
// currently only one place.. so
markerDragStart = true;
}

.....

protected void pointerDragged(final int x, final int y) {
if (!initialized) {
return;
}
if (markerDragStart)
{
//remove existing place
//create place in specified x and y
}
else
{
mapDisplay.pointerDragged(x, y);
}
}

If the above method is correct, I need to specify the new place in x and y at any drag moment. But I can create place only with wgspoints. So I need to convert (x,y) to wgspoint. How to achieve this? (There was a thread with similar problem already posted sometime back)

Please help.

Parthiban Rajendran

parthi2929
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 07/26/2009

I am trying to use following logic using bbox but not working.. please help.. :(

if (markerDragStart)
{
double BBMaxLon;
double BBMaxLat;
double BBMinLon;
double BBMinLat;
double newLon;
double newLat;

synchronized(mapDisplay)
{
BBMaxLon = mapDisplay.getBoundingBox().getWgsMax().getLon();
BBMaxLat = mapDisplay.getBoundingBox().getWgsMax().getLat();
BBMinLon = mapDisplay.getBoundingBox().getWgsMin().getLon();
BBMinLat = mapDisplay.getBoundingBox().getWgsMin().getLat();
}
double perPixelLon = (BBMaxLon - BBMinLon)/getWidth();
double perPixelLat = (BBMaxLat - BBMinLat)/getHeight();
newLon = BBMinLon + x*perPixelLon;
newLat = BBMaxLat + y*perPixelLat;
synchronized(mapDisplay)
{
mapDisplay.removeAllPlaces();
Place currentPlace = new Place(1, new PlaceLabel("location"),
markerImage, new WgsPoint(newLon, newLat));
mapDisplay.addPlace(currentPlace);
mapDisplay.setMiddlePoint(currentPlace.getWgs());
}

}
else
{
mapDisplay.pointerDragged(x, y);
}

Parthiban Rajendran

jaak
User offline. Last seen 13 hours 3 min ago. Offline
Joined: 06/19/2008

I suggest two approaches:
1) If possible use MapListener and MapClicked event, which just gives you point where user clicked.
2) Try to find out where user clicked.

For example following code works for me in Pointer events:

protected void pointerReleased(final int x, final int y) {

MapPos centerPos = map.getMap().wgsToMapPos(map.getCenterPoint().toInternalWgs(),map.getZoom());
int screenCenterX=(int) map.getWidth()/2;
int screenCenterY=(int) map.getHeight()/2;
final MapPos clickOnMap = new MapPos(centerPos.getX() - screenCenterX + x, centerPos
.getY() - screenCenterY + y, centerPos.getZoom());
final WgsPoint wgsPos = new WgsPoint(map.getMap().mapPosToWgs(clickOnMap).getX()/1000000D,map.getMap().mapPosToWgs(clickOnMap).getY()/1000000D);
System.out.println("clickOnMap wgsPoint = "+wgsPos);
map.addPlace(new Place(2, "Pressed", icon, wgsPos));
map.pointerReleased(x, y);
}

/JaakL

parthi2929
User offline. Last seen 2 years 4 weeks ago. Offline
Joined: 07/26/2009

toInternalWgs() seems to be not available in the public library?! Is the manual equivalent of it would be just multiplying decimal lon,lat by 1000000?

Parthiban Rajendran

jaak
User offline. Last seen 13 hours 3 min ago. Offline
Joined: 06/19/2008

Yes

/JaakL

Kishore
User offline. Last seen 49 weeks 2 days ago. Offline
Joined: 01/31/2011

Hi jaak,

Where do i find that pointerreleased() or pointerDragged() methods? Which listener i have to implement?

Thanks,
Kishore

Regards,
Kishore

Kishore
User offline. Last seen 49 weeks 2 days ago. Offline
Joined: 01/31/2011

Hi Jaak,

I am trying to implement it in Android. Not getting any solution. Please show me a way.

Regards,
Kishore

jaak
User offline. Last seen 13 hours 3 min ago. Offline
Joined: 06/19/2008

These pointer methods are for J2ME only, not in Android. There are other methods like onTouch in Android UI (View.OnTouchListener) which do similar things there.

/JaakL

Kishore
User offline. Last seen 49 weeks 2 days ago. Offline
Joined: 01/31/2011

Hi Jaak,

How do I get the Place object to move/remove, when I click on a Place marker?
And when I am dragging, the whole Mapview is moving and ACTION_MOVE action will be performed in OnTouchListener of MapView. Please help me out.

Regards,
Kishore