eclipse - MAP VIEW IN ANDROID - JUST SHOWING TILES. LIVE MAP VIEW IS NOT THERE -
i tried getting location on map following code not getting live map view..... tiles grids etc...map view not visible.. please see code , help.
androidgpstrackingactivity.java
package com.androidhive.dashboard; import java.util.list; import com.google.android.maps.geopoint; import com.google.android.maps.mapactivity; import com.google.android.maps.mapcontroller; import com.google.android.maps.mapview; import com.google.android.maps.overlay; import com.google.android.maps.overlayitem; import android.app.activity; import android.content.intent; import android.graphics.drawable.drawable; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.toast; import androidhive.dashboard.r; public class androidgpstrackingactivity extends mapactivity { button btnshowlocation; mapview mapview; list<overlay> mapoverlays; additemizedoverlay itemizedoverlay; geopoint geopoint; // map controllers mapcontroller mc; double latitude; double longitude; overlayitem overlayitem; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.map_view); gpstracker gps = new gpstracker(androidgpstrackingactivity.this); latitude = gps.getlatitude(); longitude = gps.getlongitude(); toast.maketext(getapplicationcontext(), "your location - \nlat: " + latitude + "\nlong: " + longitude, toast.length_long).show(); mapview = (mapview) findviewbyid(r.id.mapview); mapview.setbuiltinzoomcontrols(true); mapoverlays = mapview.getoverlays(); // geopoint place on map geopoint = new geopoint((int) (latitude * 1e6), (int) (longitude * 1e6)); // drawable marker icon drawable drawable_user = this.getresources() .getdrawable(r.drawable.mark_red); itemizedoverlay = new additemizedoverlay(drawable_user, this); // map overlay item overlayitem = new overlayitem(geopoint, "your location", "that you!"); itemizedoverlay.addoverlay(overlayitem); mapoverlays.add(itemizedoverlay); itemizedoverlay.populatenow(); mc = mapview.getcontroller(); mc.animateto(geopoint); mapview.postinvalidate(); } @override protected boolean isroutedisplayed() { // todo auto-generated method stub return false; } }
$
additemmizedoverlay.java
package com.androidhive.dashboard; import java.util.arraylist; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.graphics.drawable.drawable; import android.view.motionevent; import android.widget.toast; import com.google.android.maps.geopoint; import com.google.android.maps.itemizedoverlay; import com.google.android.maps.mapview; import com.google.android.maps.overlayitem; /** * class used place marker or overlay items on map * */ public class additemizedoverlay extends itemizedoverlay<overlayitem> { private arraylist<overlayitem> mapoverlays = new arraylist<overlayitem>(); private context context; public additemizedoverlay(drawable defaultmarker) { super(boundcenterbottom(defaultmarker)); } public additemizedoverlay(drawable defaultmarker, context context) { this(defaultmarker); this.context = context; } @override public boolean ontouchevent(motionevent event, mapview mapview) { if (event.getaction() == 1) { geopoint geopoint = mapview.getprojection().frompixels( (int) event.getx(), (int) event.gety()); // latitude double lat = geopoint.getlatitudee6() / 1e6; // longitude double lon = geopoint.getlongitudee6() / 1e6; toast.maketext(context, "lat: " + lat + ", lon: "+lon, toast.length_short).show(); } return false; } @override protected overlayitem createitem(int i) { return mapoverlays.get(i); } @override public int size() { return mapoverlays.size(); } @override protected boolean ontap(int index) { overlayitem item = mapoverlays.get(index); alertdialog.builder dialog = new alertdialog.builder(this.context); dialog.settitle(item.gettitle()); dialog.setmessage(item.getsnippet()); dialog.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { } }); dialog.show(); return true; } public void addoverlay(overlayitem overlay) { mapoverlays.add(overlay); } public void populatenow(){ this.populate(); } }
map_view.xml
<?xml version="1.0" encoding="utf-8"?> <com.google.android.maps.mapview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:enabled="true" android:apikey="api_key" />
$
android api v1 deprecated , can't have new api key generated it. have generated 1 api v2.
the easiest way migrate v2 remove code have , follow link: https://developers.google.com/maps/documentation/android/start
Comments
Post a Comment