PDA

View Full Version : GOOGLE MAP API V2



antimat
سه شنبه 27 خرداد 1393, 19:03 عصر
با سلام ، من کلی تو این سایت و سایتهای دیگه در این مورد گشتم و چندین نمونه کد و آموزش رو هم امتحان کردم ولی موفق نشدم این برنامه رو اجرا کنم از دوستان اگه کسی google map api v2 رو تونسته بنویسه و اجراش کنه لطفا یه آموزش با جزییات بذاره و خیال همه رو راحت کنه .

parvizwpf
سه شنبه 27 خرداد 1393, 19:12 عصر
کجاش مشکل دارید؟

antimat
چهارشنبه 28 خرداد 1393, 09:22 صبح
وقتی اجراش میکنم Unfortuntely , GMap has stopped میده همه چیزشم درسته نمیدونم کجا مشکل داره!!

parvizwpf
چهارشنبه 28 خرداد 1393, 14:45 عصر
ببین برای بررسی دقیق لازمه هر چی تا حالا برای مپ نوشتی بزاری اینجا تا ببینیم کجای کار مورد داره . هم manifest هم کلاس کد هم layout

antimat
چهارشنبه 28 خرداد 1393, 19:15 عصر
من چندین روش کدنویسی رو از چندین سایت امتحان کردم نمیدونم کجا مشکل دارم این یه نمونش:


package com.example.googlev2map;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor Factory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;


import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;


public class MainActivity extends FragmentActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


GoogleMap googleMap;
googleMap = ((SupportMapFragment)(getSupportFragmentManager(). findFragmentById(R.id.map))).getMap();
LatLng latLng = new LatLng(-33.796923, 150.922433);

googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.defaultMarker(Bitmap DescriptorFactory.HUE_AZURE)));


googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(t rue);
googleMap.animateCamera(CameraUpdateFactory.newLat LngZoom(latLng, 10));

}
}


و

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlev2map"
android:versionCode="1"
android:versionName="1.0" >


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





<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_G SERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>




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






<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.googlev2map.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyABTF07dno7RsfgeuNMAQv7IZENR0H7oOY"/>

<meta-data
android:name="com.google.android.gms.version"
android:value="4132500" />
</application>


</manifest>





و

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >


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


</RelativeLayout>






120299

parvizwpf
پنج شنبه 29 خرداد 1393, 17:40 عصر
- در کلاس از Activity استفاده کرده و از fragmentActivity استفاده نکنید.
- بحای SupportMapFragment از MapFragment استفاده کنید.
- دسترسی های مورد نیاز در manifest:



<permission
android:name="com.example.googlev2map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_G SERVICES" />
<uses-permission android:name="com.example.googlev2map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

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

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your API KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />



- در لی اوت هم بجای SupportMapFragment از mapFragment استفاده نمایید.

- آخرین ورژن google play services نیاز هست . در واقع باید به یک دستگاه واقعی خروجی رو تست بگیرید. سیمولاتور استفاده نکنید. ضمنا هر ورژن google play services که استفاده میکنید توی اون دیوایس باید همون یا ورژن بالاتر نصب باشه.