1

Until I changed the package name all was working fine on my device... once pkg was changed, camera is not moving to initial latlng. also, the markers are not getting displayed.

package com.vaishnavismeclass.divyadesammap.english;

import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;



import android.app.Activity;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity implements OnMarkerClickListener {


    private GoogleMap mMap;

    /*
     * declaration of all the parameters
     * to display paasurams
     * on a list
     * this will act as query critiera
     */
    public final static String EXTRA_CATEGORY = "com.vaishnavismeclass.divyadesamsmap.englis.CATEGORY";
    public final static String EXTRA_START = "com.vaishnavismeclass.divyadesamsmap.englis.START";
    public final static String EXTRA_ENDING = "com.vaishnavismeclass.divyadesamsmap.englis.ENDING";
    public final static String EXTRA_PASURAMNUMBER = "com.vaishnavismeclass.divyadesamsmap.englis.PASURAMNUMBER";
    public final static String EXTRA_AAYIRAM = "com.vaishnavismeclass.divyadesamsmap.englis.AAYIRAM";
    public final static String EXTRA_AZHWAAR = "com.vaishnavismeclass.divyadesamsmap.englis.AZHWAAR";
    public final static String EXTRA_MANGALASASANAMON = "com.vaishnavismeclass.divyadesamsmap.englis.MANGALASASANAMON";
    public final static String EXTRA_SUBCATEGORY = "com.vaishnavismeclass.divyadesamsmap.englis.SUBCATEGORY";
    public final static String EXTRA_TITLE = "com.vaishnavismeclass.divyadesamsmap.englis.TITLE";

    /*
     * 
     * Define latlng
     * of all the divyadesams
     * with a variable
     */
    static final LatLng lTiruSalagramam= new LatLng(28.816885 , 83.870814);



    /*
     * 
     * Define divyadesam string
     * for passing to the database
     * to query
     */
    static final String mTiruSalagramam = "Tiru Salagramam";


    /*
     * Define markers
     * as divyadesams without ( - and space
     * 
     */
    Marker TiruSalagramam;

    @Override
    public boolean onMarkerClick(Marker marker) {
        Intent intent = new Intent(getApplicationContext(),
                Paasurams.class);
/*
 * Create intent data
 * and pass to respective
 * pages
 */
        Log.d("VC","Marker selected is "+marker.toString());
        if (marker.equals(TiruSalagramam)){intent.putExtra(EXTRA_MANGALASASANAMON,mTiruSalagramam );}


        startActivity(intent);
        return false;
    }

    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

     // Sets the map type to be "hybrid"
        mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        /*
         * 
         * Setup my location
         * 
         * 
         */
        if (mMap == null)
            return; // Google Maps not available
        try {
            MapsInitializer.initialize(this);
        }
        catch (GooglePlayServicesNotAvailableException e) {
            Log.e("VC", "Have GoogleMap but then error", e);
            return;
        }
        mMap.setMyLocationEnabled(true);
     // Getting LocationManager object from System Service LOCATION_SERVICE
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        // Creating a criteria object to retrieve provider
        Criteria criteria = new Criteria();

        // Getting the name of the best provider
        String provider = locationManager.getBestProvider(criteria, true);

        // Getting Current Location
        Location location = locationManager.getLastKnownLocation(provider);

        if(location!=null){
        // Getting latitude of the current location
        double latitude = location.getLatitude();

        // Getting longitude of the current location
        double longitude = location.getLongitude();

        // Creating a LatLng object for the current location
        LatLng latLng = new LatLng(latitude, longitude);

        LatLng myPosition = new LatLng(latitude, longitude);

        mMap.addMarker(new MarkerOptions().position(myPosition).title("Current Location"));

        /*
         * Show the location name
         * on the marker always
         * 
         */
        //TiruSalagramam.showInfoWindow();
        /*
         * Do basic setup if required
         */
        setUpMapIfNeeded();

      //
        GoogleMapOptions options = new GoogleMapOptions();
        options.mapType(GoogleMap.MAP_TYPE_SATELLITE)
        .compassEnabled(true)
        .rotateGesturesEnabled(true)
        .tiltGesturesEnabled(true);
        /*
         * Focus camera to Nagpur
         */
        CameraUpdate center=
                CameraUpdateFactory.newLatLng(new LatLng(21.153889,
                                                         79.083056));
            CameraUpdate zoom=CameraUpdateFactory.zoomTo(4);

            mMap.moveCamera(center);
            mMap.animateCamera(zoom);

        /*
         * customize the marker color
         */

            TiruSalagramam= mMap.addMarker(new MarkerOptions().position(lTiruSalagramam).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)).title(mTiruSalagramam));

            mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                @Override
                public void onInfoWindowClick(Marker marker) {
                    // TODO Auto-generated method stub
                    Intent intent = new Intent(getApplicationContext(),
                            Paasurams.class);
                    if (marker.equals(TiruSalagramam)){intent.putExtra(EXTRA_MANGALASASANAMON,mTiruSalagramam );}

                 startActivity(intent);             


                }

            }
            );
    }

    }

    private void setUpMapIfNeeded() {
        // TODO Auto-generated method stub
         // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                                .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                // The Map is verified. It is now safe to manipulate the map.

            }
        }
    }
    }

I have removed most other markers and related code to accommodate the size.

Manifest is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.vaishnavismeclass.divyadesammap.english"
    android:versionCode="2"
    android:versionName="2.2" >

    <permission
        android:name="com.vaishnavismeclass.divyadesammap.english.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

    <uses-permission android:name="com.vaishnavismeclass.divyadesammap.english.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" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.vaishnavismeclass.divyadesammap.english.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>
        <activity
            android:name="com.vaishnavismeclass.divyadesammap.english.Paasurams"
            android:label="Paasurams"
            android:parentActivityName="com.vaishnavismeclass.divyadesammap.english.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.vaishnavismeclass.divyadesammap.english.MainActivity" />
        </activity>

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

</manifest>
Suresh PB
  • 169
  • 1
  • 2
  • 16

3 Answers3

0

Try it... select the app and go to the project and click on clean ,and after it build it ...

Dhiman
  • 146
  • 1
  • 5
  • 21
0

When you change the package name make sure that a new key is generated and the new key is copied to the android manifest since to display maps a key with the package name is used.

EDIT

You are missing <uses-library android:name="com.google.android.maps" /> and use

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

in your xml file to display map

Lal
  • 14,726
  • 4
  • 45
  • 70
  • New key has been generated...still no luck – Suresh PB Apr 08 '14 at 10:10
  • No error. Default map is rendered without any markers – Suresh PB Apr 08 '14 at 11:17
  • How did you change the package name?? – Lal Apr 08 '14 at 11:18
  • In eclipse project explorer clicked on src-package and re factored to new package name. Added manifest for reference – Suresh PB Apr 08 '14 at 11:48
  • I'm unclear about your edit. do you want me to replace instead of android:name="com.google.android.gms.maps.MapFragment" – Suresh PB Apr 09 '14 at 03:45
  • Last evening, I tried to connect my phone and connected the phone to the wifi. On the eclipse, I ran the application to the phone. It worked as expected without any edit. Now, without the wifi also it works. No changes were made, but it worked. The same when downloaded from play.google.com errors out saying "MainActivity" is not present. I'm confused. – Suresh PB Apr 09 '14 at 03:48
  • Did you list the activity within your AndroidManifest.xml file? – Lal Apr 09 '14 at 05:40
  • Acitivity has been listed, also listed the parent activity attribute. – Suresh PB Apr 09 '14 at 05:45
  • Try this [link](http://stackoverflow.com/questions/16636039/java-lang-classnotfoundexception-after-changing-nothing-in-the-project-but-upgra/16636127#16636127) – Lal Apr 09 '14 at 05:50
0

Try this link

or

this link

Might be helpfull..

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. Clean all projects afterwards and see what happens.
Community
  • 1
  • 1
Lal
  • 14,726
  • 4
  • 45
  • 70