i trying draw polygon on mapfragment cannot render. using code example developer docs no avail. new must missing obvious cannot work out is. not getting runtime errors.
here relevant bit of main activity.
public class userlocation<mainactivity> extends activity { blah blah... //set initial map fragment view map = ((mapfragment)getfragmentmanager().findfragmentbyid(r.id.map)).getmap(); latlng startpoint = new latlng(-30.89,24.26); //see use of cameraposition.builder here gives cool perspective view on map. see use of map.animatecamera using method too; cameraposition cameraposition = new cameraposition.builder().target(startpoint).tilt(60).zoom(6).bearing(0). build(); map.animatecamera(cameraupdatefactory.newcameraposition(cameraposition)); //try add polgyon list<latlng> points = arrays.aslist(new latlng(18.39416, -33.97885), new latlng(18.45116, -33.97885), new latlng(18.45116, -33.91077), new latlng(18.39416, -33.91077), new latlng(18.39416, -33.97885)); polygonoptions options = new polygonoptions(); options.addall(points); options.fillcolor(color.red); map.addpolygon(options);
the xml file
<textview android:id="@+id/header" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <fragment android:id="@+id/map" class="com.google.android.gms.maps.mapfragment" android:layout_width="match_parent" android:layout_height="match_parent" /> <imagebutton android:id="@+id/mainnavigationbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginleft="120dp" android:onclick="onclick_launch_mainnavigation" android:alpha="0.8" android:src="@drawable/copbutton"/> <spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="17dp" android:entries="@array/crime_arrays" android:prompt="@string/crime_prompt" /> </framelayout>
the documents suggest simple process i'm stumped. in advance advice.
your code should work. be, accidently switching longitude/latitude, since drawing polygons (24.26,-30.89) move camera (-30.89,24.26).
to ensure @ right area, create button calls
private function onbuttonclick(){ latlng startpoint = new latlng(24.26,-30.89); cameraposition cameraposition = new cameraposition.builder().target(startpoint).tilt(60).zoom(6).bearing(0). build(); map.animatecamera(cameraupdatefactory.newcameraposition(cameraposition)); }
Comments
Post a Comment