1
votes

I want to show current location in map using Google Map v2. I create sha key and generate API key and also integrate with androidmanifest.xml. I download example of following link:

http://wptrafficanalyzer.in/blog/showing-current-location-in-google-maps-using-api-v2-with-supportmapfragment/

I also give internet permission and other but in my log-cat following error display.

11-20 11:09:59.190: E/dalvikvm(719): Could not find class 'com.google.android.gms.maps.model.LatLng', referenced from method in.wptrafficanalyzer.locationingooglemapv2.MainActivity.onLocationChanged
11-20 11:09:59.190: W/dalvikvm(719): VFY: unable to resolve new-instance 460 (Lcom/google/android/gms/maps/model/LatLng;) in Lin/wptrafficanalyzer/locationingooglemapv2/MainActivity;
11-20 11:09:59.190: D/dalvikvm(719): VFY: replacing opcode 0x22 at 0x0010
11-20 11:09:59.220: D/dalvikvm(719): DexOpt: unable to opt direct call 0x0cdc at 0x12 in Lin/wptrafficanalyzer/locationingooglemapv2/MainActivity;.onLocationChanged
11-20 11:09:59.482: D/AndroidRuntime(719): Shutting down VM
11-20 11:09:59.482: W/dalvikvm(719): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-20 11:09:59.501: E/AndroidRuntime(719): FATAL EXCEPTION: main
11-20 11:09:59.501: E/AndroidRuntime(719): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.locationingooglemapv2/in.wptrafficanalyzer.locationingooglemapv2.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.os.Looper.loop(Looper.java:137)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-20 11:09:59.501: E/AndroidRuntime(719):  at java.lang.reflect.Method.invokeNative(Native Method)
11-20 11:09:59.501: E/AndroidRuntime(719):  at java.lang.reflect.Method.invoke(Method.java:511)
11-20 11:09:59.501: E/AndroidRuntime(719):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-20 11:09:59.501: E/AndroidRuntime(719):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-20 11:09:59.501: E/AndroidRuntime(719):  at dalvik.system.NativeStart.main(Native Method)
11-20 11:09:59.501: E/AndroidRuntime(719): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-20 11:09:59.501: E/AndroidRuntime(719):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.Activity.setContentView(Activity.java:1867)
11-20 11:09:59.501: E/AndroidRuntime(719):  at in.wptrafficanalyzer.locationingooglemapv2.MainActivity.onCreate(MainActivity.java:27)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.Activity.performCreate(Activity.java:5008)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-20 11:09:59.501: E/AndroidRuntime(719):  ... 11 more
11-20 11:09:59.501: E/AndroidRuntime(719): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
11-20 11:09:59.501: E/AndroidRuntime(719):  ... 21 more
11-20 11:09:59.501: E/AndroidRuntime(719): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
11-20 11:09:59.501: E/AndroidRuntime(719):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-20 11:09:59.501: E/AndroidRuntime(719):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-20 11:09:59.501: E/AndroidRuntime(719):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-20 11:09:59.501: E/AndroidRuntime(719):  at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
11-20 11:09:59.501: E/AndroidRuntime(719):  ... 24 more

Now what i can do for displaying map?

2
Have you add the google play service library...vinay Maneti
yes but it display error when add google play service library.jack
i cant add external library in project. what is the reason for that?jack
that Google play service library should be in sample directory... follow the link docs.google.com/document/…vinay Maneti
i know i already import google play library from following path: android-sdk->extras->google->google_play_services->libproject.jack

2 Answers

2
votes

Maps Activity

public class MainActivity extends FragmentActivity {


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



}

activity_main

<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"
    tools:context=".MainActivity" >

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>

Manifest file

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

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

    <permission
        android:name="YourPackageName.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="YourPackageName.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <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="YourPackageName.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.gms.version"
            android:value="4030500" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YourKey" />
    </application>`enter code here`

</manifest>

Open sdk manager and download google play service under extras, you will get two libraries google-play-services_lib.jar and google-play-services.jar. You can find these libraries under google play service in extras. You have to copy these two libraries and paste under lib folder in your app and also add these libraries under java Build path.

0
votes

make sure by going to google api console go to services in go down you will find google map v2 eanble it... enter image description here To add a reference to a library project, follow these steps:

    1. Make sure that both the project library and the application project that depends on it are in your workspace. If one of the projects is missing, import it into your workspace.
    2. In the Package Explorer, right-click the dependent project and select Properties.
    3.In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
    4.Click Add to open the Project Selection dialog.
    5.From the list of available library projects, select a project and click OK.
    6.When the dialog closes, click Apply in the Properties window.
    7.Click OK to close the Properties window.

how to add reference Google play Library

Android Library Projects