Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
5
Erster Beitrag:
vor 5 Jahren, 5 Monaten
Letzter Beitrag:
vor 5 Jahren, 5 Monaten
Beteiligte Autoren:
Arie, Paul Murray

WDM17-ANDROID - Map Control - Zoom Level Not Working

Startbeitrag von Paul Murray am 26.01.2013 03:58

Greetings All,

I am having trouble with setting the zoom level for a map control in Android.

In the following code I do the following:

1) Set Lat/Long for 1st marker - WORKS
2) Set Lat/Long for 2nd marker - WORKS
3) Get the Distance between the two markers - WORKS
4) Derive the lat/long at the midpoint between both markers - WORKS
5) Center the map on the midpoint between the two markers - WORKS
6) Set the zoom level using MAP_FT_MAP..ZOOM - DOES NOT WORK

For item 6 I do NOT get an error. The map paints up okay and the Info message window says that the zoom level is 18 (or something like that based on the formula).

But when I press the map, the code in the PRESS even fires and reports that the zoom level is 11.

I thought maybe I have to recall a function to repaint the map after I set the zoom level, but I cannot find such function.

Can someone let me know if A) they have been able to set the zoom level in an Android map control.

Can someone possibly let me know what I might be missing in the code below?

By the way, none of my attempts to change markers works. Has anyone had success with doing this with an Android map control?

Thanks in advance!!

Paul


INITIALIZATION OF MAP_FT_MAP


// Delete all the markers from the control
MapDeleteAll()

// Returns the point of the map corresponding to the current position of the user
MyPosition is géoPosition

IF gsAirport = "JFK" THEN
MyPosition..Latitude = grVAA_JFK_LAT
MyPosition..Longitude = grVAA_JFK_LONG
ELSE IF gsAirport = "EWR" THEN
MyPosition..Latitude = grVAA_EWR_LAT
MyPosition..Longitude = grVAA_EWR_LONG
END

MyMarker is Marker
MyMarker..Position = MyPosition
MyMarker..Name = "Me"
MapAddMarker(MAP_FT_Map,MyPosition)

CarPosition is géoPosition
//if gstestmode = "True" then
// CarPosition..Latitude = 40.64375
// CarPosition..Longitude = -73.78403
//else
CarPosition..Latitude = grCar_lat
CarPosition..Longitude = grCar_long
//end

CarMarker is Marker
CarMarker..Position = CarPosition
//CarMarker..Image = "1234.png"
CarMarker..Name = gsCarNo
CarMarker..Description = "CAR 1234"
MapAddMarker(MAP_FT_Map,CarMarker)

rDistance is real
rDistance = geoDistance(MyPosition,CarPosition,geoMile)

nZoomlevel is int
nZoomlevel = 1
rIntermediatevalue is real

//L = log2(E/D)+1
//xZoomlevel = log2(21.638,8/xDistance)+1
rIntermediatevalue = 21638.8/rDistance
nZoomlevel = Log(rIntermediatevalue)/Log(2)+1
//my poor attempts to increase zoom level because I didn't realize that it did not work at all
IF nZoomlevel< 17 THEN
nZoomlevel = nZoomlevel + 5
END

gxLat1 = CarPosition..Latitude
gxLong1 = CarPosition..Longitude
gxLat2 = MyPosition..Latitude
gxLong2 = MyPosition..Longitude

//This is a simple way to get lat/long for a midpoint between two points for short distances as it does not take into account the curve of the earth, etc.
gxlat3 = (gxLat1 + gxLat2)/2
gxLong3 = (gxLong1 + gxLong2)/2

CenterMapPosition is géoPosition
CenterMapPosition..Latitude = gxlat3
CenterMapPosition..Longitude = gxLong3

Info("Distance in Miles",rDistance)
Info("ZoomLevel",nZoomlevel)
Info("Lat3/Long3",gxlat3 + "," + gxLong3)

//MAP_FT_Map..Zoom = 18
//MAP_FT_Map..Zoom = nZoomlevel

MapDisplayPosition(MAP_FT_Map, CenterMapPosition)

MAP_FT_Map..Zoom = nZoomlevel
MAP_FT_Map..MyPosition..Longitude))

PRESS/LEFT BUTTON DOWN OF MAP_FT_MAP


iResult is int
iResult = MAP_FT_Map..Zoom
Info("ZoomLevel",iResult)






Antworten:

Paul,
maybe you can try to use the Java classes directly.
Afaik the WM map control is based on the standard Google/java map control, as are all other controls. In java they are called "views"

This code sets the visibility of an image control
Put it in a global procedure and click in the header-bar of this procedure to switch it to a Java procedure. You can call this procedure like any other w-language procedure.


import android.view.View;

public static void testjava_visible(String sControl, boolean bVisible)
{
View vw1 = getView(sControl);
if(bVisible){
vw1.setVisibility(View.VISIBLE); // 0
}
else {
vw1.setVisibility(View.INVISIBLE); // 4
}
}

Here is another one to CAST the view-object to an image-view. Then you can access all imageview specific members.
This way you should also be able to get to the mapview and set the zoom-lever through Java.
http://developer.android.com/reference/com/google/android/gms/maps/MapView.html

von Arie - am 26.01.2013 17:09
Forgot the example ot the CAST to an imageview - here it is

import android.view.View;
import android.widget.ImageView;

public static void testjava_image(String sControl)
{
ImageView image = (ImageView) getView(sControl);
image.scrollBy(100,100);
image.scrollTo(100,100);
}

von Arie - am 26.01.2013 17:11
BTW: these functions do not work in the Windev simulator.
You have to test it using a real device or the java emulator.
Use InAndroidMode and InAndroidSimulatorMode to be able to use the simulator without running into errors, by bypassing this code

von Arie - am 26.01.2013 17:22
All,

Oddly, the problem has gone away. Now when I set the zoom level, I end up with a map that has the correct zoom level. I don't know why.

At this point it pretty much works the way I want it to.

The only problem is that my calculation for determining the zoom level is wanting. It works okay, but sometimes you have to manually zoom out to see both markers.

I will work on that and post back the solution.

Paul

von Paul Murray - am 28.01.2013 18:02
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.