简体   繁体   中英

Google maps navigation to a particular place using latitude and longitude

I am a newbie to Android development, I am working on Google maps. I am trying to navigate to particular location by using latitude and longitude. I have give required permissions in manifest file, but I couldn't do navigation, please help me.

MainActivity,java

package com.examp.nowmap;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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;

@SuppressLint("NewApi")
public class MainActivity extends Activity {
static final LatLng GOA = new LatLng(15.193588,73.942366);
private GoogleMap mapn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapn = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
    .getMap();
Marker hamburg = mapn.addMarker(new MarkerOptions().position(GOA)
    .title(LOCATION_SERVICE));

   mapn.moveCamera(CameraUpdateFactory.newLatLngZoom(GOA, BIND_ALLOW_OOM_MANAGEMENT));
   mapn.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
} 

manifest.xml

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

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

<permission
    android:name="com.examp.nowmap.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

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

<uses-permission android:name="com.examp.nowmap.package.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.examp.nowmap.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="AIzaSyBZ2omuN7djk6R8eUNLkIrn13DEvnN-q58" />

</application>
</manifest>

You do not have the permission:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

This is required to access the Google servers, I'm not sure this will fix your problem entirely, but its best to follow the actual Google API V2 tutorial for android.

click this link --> https://developers.google.com/maps/documentation/android/intro

This will help you make sure you've got everything set up right. The only other thing worth noting is make sure your working on a real device as Google maps wont work in an emulator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM