How to effectively use Google Maps API V2(with MapFragment, Google Map, Marker etc) to an older app that uses API V1(with MapView, GeoPoint etc), -
i working on google map based project on 6 months. using google maps api v1 , developer api keys. while trying release app understood google api v1 got deprecated! when read google maps api v2, found mapview, geopoint, overlayitem replaced fragment, marker, mapfragment, google map etc.
my original xml looks this
<?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:apikey="**************my old api key**************"/>
now google not provide key, need add map, , show overlay items on same. notally confused new api.
my java file looks like
public class placesmapactivity extends mapactivity { // nearest places placeslist nearplaces; // map view mapview mapview; // map overlay items list<overlay> mapoverlays; additemizedoverlay itemizedoverlay; geopoint geopoint; // map controllers mapcontroller mc; drawable defaultmarker; double latitude; double longitude; overlayitem overlayitem; string p_u_name; place reference; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.map_places); // getting intent data intent = getintent(); reference = (place) i.getserializableextra("place_reference"); // users current geo location string user_latitude = i.getstringextra("user_latitude"); string user_longitude = i.getstringextra("user_longitude"); // nearplaces list nearplaces = (placeslist) i.getserializableextra("near_places"); mapview = (mapview) findviewbyid(r.id.mapview); mapview.setbuiltinzoomcontrols(true); mapoverlays = mapview.getoverlays(); // geopoint place on map geopoint = new geopoint((int) (double.parsedouble(user_latitude) * 1e6),(int) (double.parsedouble(user_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(); drawable drawable = this.getresources().getdrawable(r.drawable.mark_blue); itemizedoverlay = new additemizedoverlay(drawable, this); mc = mapview.getcontroller(); // these values used map boundary area // area can see markers on screen int minlat = integer.max_value; int minlong = integer.max_value; int maxlat = integer.min_value; int maxlong = integer.min_value; // check null in case null if (nearplaces.results != null) { // loop through places (place place : nearplaces.results) { latitude = place.geometry.location.lat; // latitude longitude = place.geometry.location.lng; // longitude // geopoint place on map geopoint = new geopoint((int) (latitude * 1e6), (int) (longitude * 1e6)); // map overlay item overlayitem = new overlayitem(geopoint,"0",place.reference); itemizedoverlay.addoverlay(overlayitem); // calculating map boundary area minlat = (int) math.min( geopoint.getlatitudee6(), minlat ); minlong = (int) math.min( geopoint.getlongitudee6(), minlong); maxlat = (int) math.max( geopoint.getlatitudee6(), maxlat ); maxlong = (int) math.max( geopoint.getlongitudee6(), maxlong ); } mapoverlays.add(itemizedoverlay); // showing overlay items itemizedoverlay.populatenow(); } // adjusting zoom level can see markers on map mapview.getcontroller().zoomtospan(math.abs( minlat - maxlat ), math.abs( minlong - maxlong )); mapcontroller controller = mapview.getcontroller(); controller.setzoom(15); // showing center of map mc.animateto(new geopoint((maxlat + minlat)/2, (maxlong + minlong)/2 )); mapview.postinvalidate(); } @override protected boolean isroutedisplayed() { return false; } }
i want know if there means use old code support google maps api v2?
the easiest way migrate v2 remove code have , write scratch.
android api v1 , v2 not map 1 1.
thank you
Comments
Post a Comment