Hi.
I completed the Android SDK Hello, MapView tutorial and have a working (but basic!) native app that displays a map with a single marker on it.
The code is minimal and looked at first to be simple enough to transplant to a B4A library:
and
I started a new library aiming first to just add a MapView to a B4A app and straightaway found it a non-starter.
A MapView can only be added to an activity that extends the MapActivity class - you cannot add one to an activity that extends the Activity class.
Here's the library code:
The library compiles but when i try to use it there is no GeographMap type available in the code completion list.
I'm assuming that this is because the B4A activity extends Activity and NOT MapActivity..?
Looking at the compiled B4A source for any B4A project i see the activity extends Activity (as expected) and implements B4AActivity.
What seemed like a simple task now looks to be unworkable or impossible.
Even if i could develop a B4AMapActivity there would be no way to integrate it into the B4A IDE - we have activity, code and service modules and i'm assuming this is where a 'map module' would also be available as a new module option?
So B4A does not support MapActivity and there's no way to add it - is that correct?
A solution for my app might be to compile a native MapView activity that contains all the functionality i require and then when my app requires the map simply use an INTENT to start my native sdk MapView app - hopefully i could pass values to the MapView app from my B4A app so the MapView app knows where to create map markers.
Trouble is i want the map to display in a tab in a tabhost which i cannot do with B4A.
Another idea was to import my compiled B4A app into Eclipse and look at modifying it - adding native SDK code and then re-compiling it.
Is that possible - to take a working compiled B4A project and add native SDK code to it and then re-compile?
Thanks.
Martin.
I completed the Android SDK Hello, MapView tutorial and have a working (but basic!) native app that displays a map with a single marker on it.
The code is minimal and looked at first to be simple enough to transplant to a B4A library:
B4X:
package com.martin.pearman.hellogooglemaps;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import java.util.List;
public class MultiResultsMap extends MapActivity {
List<Overlay> mapOverlays;
Drawable drawable;
GeographOverlay geographOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView=(MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays=mapView.getOverlays();
drawable=this.getResources().getDrawable(R.drawable.geograph_icon);
geographOverlay=new GeographOverlay(drawable);
GeoPoint point=new GeoPoint(19240000, -99120000);
OverlayItem overlayItem=new OverlayItem(point, "", "");
geographOverlay.addOverlay(overlayItem);
mapOverlays.add(geographOverlay);
}
@Override
protected boolean isRouteDisplayed(){
return false;
}
}
and
B4X:
package com.martin.pearman.hellogooglemaps;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import java.util.ArrayList;
public class GeographOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public GeographOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int index) {
return mOverlays.get(index);
}
@Override
public int size() {
return mOverlays.size();
}
}
I started a new library aiming first to just add a MapView to a B4A app and straightaway found it a non-starter.
A MapView can only be added to an activity that extends the MapActivity class - you cannot add one to an activity that extends the Activity class.
Here's the library code:
B4X:
package uk.co.martinpearman.geographmap;
import com.google.android.maps.MapView;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;
@ActivityObject
@Author("Martin Pearman")
@Hide
@ShortName("GeographMap")
@Version((float) 1.0)
public class GeographMap extends ViewWrapper<MapView> {
@Hide
public void innerInitialize(BA ba, String eventName, boolean keepOldObject) {
if (!keepOldObject) {
setObject(new MapView(ba.context, "0k1SIJwKfCiZTK7UT7nWbsF2jwt9BgsyP5H5SLQ"));
super.innerInitialize(ba, eventName, true);
}
}
}
The library compiles but when i try to use it there is no GeographMap type available in the code completion list.
I'm assuming that this is because the B4A activity extends Activity and NOT MapActivity..?
Looking at the compiled B4A source for any B4A project i see the activity extends Activity (as expected) and implements B4AActivity.
What seemed like a simple task now looks to be unworkable or impossible.
Even if i could develop a B4AMapActivity there would be no way to integrate it into the B4A IDE - we have activity, code and service modules and i'm assuming this is where a 'map module' would also be available as a new module option?
So B4A does not support MapActivity and there's no way to add it - is that correct?
A solution for my app might be to compile a native MapView activity that contains all the functionality i require and then when my app requires the map simply use an INTENT to start my native sdk MapView app - hopefully i could pass values to the MapView app from my B4A app so the MapView app knows where to create map markers.
Trouble is i want the map to display in a tab in a tabhost which i cannot do with B4A.
Another idea was to import my compiled B4A app into Eclipse and look at modifying it - adding native SDK code and then re-compiling it.
Is that possible - to take a working compiled B4A project and add native SDK code to it and then re-compile?
Thanks.
Martin.