Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Android程序中访问google地图_Android_Google Maps - Fatal编程技术网

无法在Android程序中访问google地图

无法在Android程序中访问google地图,android,google-maps,Android,Google Maps,在这段代码中我有一些问题,在这里我无法访问谷歌地图,方块出现在地图的地方。谁能帮我解决这个问题 java类 软件包com.android.gpsapp import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import com.google.android.maps.GeoPoint; import com.googl

在这段代码中我有一些问题,在这里我无法访问谷歌地图,方块出现在地图的地方。谁能帮我解决这个问题

java类

软件包com.android.gpsapp

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

 public class GPSApp extends MapActivity
 {
  MapView mapView; 
  MapController mc;
  GeoPoint p;

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

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

    LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
    View zoomView = mapView.getZoomControls(); 

    zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT)); 

    mapView.displayZoomControls(true);

    mc = mapView.getController();

    String coordinates[] = {"26.456435","80.330606"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    p = new GeoPoint(
        (int) (lat * 1E6), 
        (int) (lng * 1E6));

    mc.animateTo(p);
    mc.setZoom(17); 
    mapView.invalidate();

    mapView.setSatellite(true);
    mapView.setStreetView(true);
    mapView.setTraffic(true);
}

  @Override
   protected boolean isRouteDisplayed() {
     // TODO Auto-generated method stub
      return false;
    }
 }
我已经给出了Main.xml和API_键

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

   <LinearLayout android:id="@+id/zoom" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    /> 

   <com.google.android.maps.MapView 
   android:id="@+id/mapView" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:enabled="true"
   android:clickable="true"
   android:apiKey="API_Key"
   /> 

</RelativeLayout>

AndroidManifes.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.android.gpsapp"
     android:versionCode="1"
     android:versionName="1.0">
    <application android:label="@string/app_name" >

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

    <activity android:name="GPSApp" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
   </application>
  <uses-permission android:name="android.permission.INTERNET" />
</manifest> 

尝试扩展碎片活动

public class Maps extends FragmentActivity {
    GoogleMap map;
    double lat;
    double lan;
    boolean flag = false;

    // private LocationManager lm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapptry);

        map = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();
             }
        }
您可以尝试将
移动到
之前,因为Android过去对这类事情很挑剔

如果没有帮助,请尝试在模拟器或设备上运行“地图”应用程序。如果它表现出同样的问题,那么问题在于你从谷歌下载地图信息的能力


如果“地图”应用程序工作,而您的应用程序不工作,则您的API密钥不正确,例如尝试在“地图V1”应用程序上使用“地图V2”API密钥。您的代码是为Maps V1设置的,您无法再获取Maps V1 API密钥。你应该考虑切换到使用地图V2,因为地图V1被正式贬低。

< P>我可以想到的主要问题是你试图实现<代码>谷歌地图API V1/<代码>,而当前的谷歌地图API版本是2。因此,或者您正试图将Google Maps API V2键与Google Maps API V1一起使用,在这种情况下,您描述的问题将出现(没有地图,只有正方形)‏ (使用缩放控件)

如果您确实生成了一个API V1密钥(我真的很怀疑…),那么问题可能出在您在Google API控制台中定义应用程序的方式上

无论如何,我建议您转到Google API v2,因为API V1已被弃用

以下是我写的一篇关于如何在应用程序中实现Google Maps API V2的博文:


您是在emulator或设备上运行吗?我正在尝试扩展FragmentActivity,但出现错误。您能解释一下吗。导入此导入android.support.v4.app.FragmentActivity;另外,请转到项目->属性->java构建路径->库->添加外部jar并添加,然后转到\android sdks\extras\android\support\v4并选择android-support-v4.jar。。这将消除您的错误。我正在使用netbeans,它无法选择此jar。一旦我选择了这个jar,如果我再次转到属性,它就不会选择jar。。所以我想我不能回答你的问题。对不起。但理想情况下,你就是这样做的。