0

Нужна срочная помощь - использовался предыдущий API Карт - после вставки следующего фрагмента кода для API карт v2 карта не загружается. CustomMapView - это класс java, который наследует MapView. Не можете понять, какие параметры необходимо заменить или удалить?Карты Google APIv2 - Карта не загружается

<com.stub.android.ui.CustomMapView 
     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="0xxxxxxxxxxxxxxxxxxxxx" /> 

Ive добавил следующее в манифесте -

<permission 
    android:name="com.stub.android.ui.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<uses-permission android:name="com.stub.android.ui.permission.MAPS_RECEIVE" /> 
<meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIxxxxxxxxxxxxxxx" /> 

Код для CustomMapView класса

public class CustomMapView extends MapView { 

public CustomMapView(Context context, String apiKey) { 
    super(context, apiKey); 
    // this.context = context; 
} 

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    try { 
     return super.dispatchTouchEvent(ev); 
    } catch (Exception ex) { 

     int zoomLevel = getZoomLevel(); 
     getController().setZoom(zoomLevel-1); 
     super.setVisibility(View.GONE); 
     super.setVisibility(View.VISIBLE); 
    } 
    return true; 
} 

@Override 
public void draw(Canvas canvas) { 
    try { 
     super.draw(canvas); 
    } catch (Exception e) { 
     int zoomLevel = getZoomLevel(); 
     getController().setZoom(zoomLevel-1); 
     super.setVisibility(View.GONE); 
     super.setVisibility(View.VISIBLE); 
    } 
} 

public CustomMapView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    // this.context = context; 
} 

public CustomMapView(Context context, AttributeSet attrs) { 
    super(context, attrs); 


} 

@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    System.gc(); 
    return super.onTouchEvent(ev); 
}} 

ответ

0
<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 

<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<permission 
    android:name="com.temp.android.maps.googlev2.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

<uses-permission android:name="com.temp.android.maps.googlev2.permission.MAPS_RECEIVE" /> 
<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.Black.NoTitleBar" > 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyDp6PHK3NYNwS74cKGmX-xc4LuH_uM1mIo" /> 

    <activity 
     android:name="com.temp.android.SplashScreenActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 
+0

Я хочу понять изменения, внесенные в макет XML, а не манифест – Droido

0
Use This XML 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 


<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" /> 

+0

, как я могу включить то же самое в существующий xml-макет, упомянутый выше в вопросе, включая класс java mapview в макете, – Droido

+0

просто установите этот xml в существующий xml-код ... и запустите его ... он будет работать правильно ... –

+0

ваш не получите меня, в таком случае, что нужно сделать для класса Java MapView? – Droido

0
This Way will be usefull for that.. 


public class HelloGoogleMaps extends MapActivity 
{ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

MapView mapView = (MapView) findViewById(R.id.mapview); 
mapView.setBuiltInZoomControls(true); 
} 
} 


<?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="API_KEY" 
/> 

<uses-library android:name="com.google.android.maps"/> 

<uses-permission android:name="android.permission.INTERNET"/> 
+0

как я могу использовать класс HelloGoogleMaps в XML-макете, как это было в моем коде выше для APIv2 - Droido

+0

его деятельность вы не можете использовать ... HelloGoogleMaps ... Для класса карты будет из библиотеки ..у не могу сделать, как что sir .......... –

+0

ive использовал этот код http://pastebin.com/87qY2hj1 это настраиваемый класс, который расширяет MapView, который я включаю через имя пакета в мой макет, coz, который является многоразовым компонент – Droido

Смежные вопросы