Java 如何在android mapview中显示地图
我在android mapview.com中创建了google地图,但在mapview.iam中使用google mapview自己的API键显示灰度 如何在没有灰度的情况下在mapview中获取地图Java 如何在android mapview中显示地图,java,android,json,Java,Android,Json,我在android mapview.com中创建了google地图,但在mapview.iam中使用google mapview自己的API键显示灰度 如何在没有灰度的情况下在mapview中获取地图 public class MainActivity extends MapActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
public class MainActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
<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" >
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:apiKey="AIzaSyBNpjyktHItZYm4no0wTvzSv8tWU5gaoy0" />
</RelativeLayout>
public类MainActivity扩展了MapActivity{
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(R.menu.activity\u主菜单);
返回true;
}
@凌驾
受保护的布尔值isRouteDisplayed(){
//TODO自动生成的方法存根
返回false;
}
}
这是我的代码,它的显示灰度。如何解决这个问题
我引用此链接,但首先显示空白输出,正如Commonware所说的,您应该使用v2 maps API。你什么时候要的钥匙?2013年3月后,您不能申请Maps v1密钥。我怀疑您可能试图将v2密钥与v1api一起使用。检查您的日志,看看是否有消息 看 另一种可能是您注册的密钥不正确。你确定你有正确钥匙的SHA1指纹吗?如果您在v1密钥可用时注册了v1密钥,是否确实使用您注册的同一密钥进行签名
此外,根据你的状态栏,你似乎没有得到一个良好的连接。谷歌地图需要网络连接。尝试打开wifi以检查它是否工作。如果是这样,很可能是因为你没有下载地图。如果wifi正常工作,请尝试在关闭wifi的情况下让应用程序运行一段时间,看看地图是否最终通过3G加载。首先,正如Commonware所说,您应该使用v2地图API。你什么时候要的钥匙?2013年3月后,您不能申请Maps v1密钥。我怀疑您可能试图将v2密钥与v1api一起使用。检查您的日志,看看是否有消息
check below example it working...
[example link1][1]
[example link2][2]
[example link3][3]
- manifest : Provide all need Permision in This Example i applied Find And Navigation
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demomap1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="com.example.demomap1.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-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.mapv2demo1.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapv2demo1.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<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" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.mapv2demo1.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=" Put Key Here" />
</application>
</manifest>
- Layout xml---I use the com.google.android.gms.maps.SupportMapFragment to show map
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/et_location"
android:layout_alignParentRight="true"
android:text="find" />
<EditText
android:id="@+id/et_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Enter Location"
android:layout_toLeftOf="@id/btn_find" />
</RelativeLayout>
<fragment
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
- Code to integration Map v2 in code the Intent is call the map app which install in phone..
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends FragmentActivity implements OnClickListener {
GoogleMap mapView;
LatLng latLong;
MarkerOptions markerOption;
Button btnFind;
EditText etLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapview)).getMap();
btnFind=(Button)findViewById(R.id.btn_find);
etLocation=(EditText)findViewById(R.id.et_location);
btnFind.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String destination=etLocation.getText().toString();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr="
+ destination));
startActivity(intent);
}
}
[1]: http://karnshah8890.blogspot.in/2013/02/google-maps-android-api-v2.html
[2]: http://android-er.blogspot.in/2012/12/a-simple-example-using-google-maps.html
[3]: http://wptrafficanalyzer.in/blog/showing-current-location-in-google-maps-using-api-v2-with-supportmapfragment/
看
另一种可能是您注册的密钥不正确。你确定你有正确钥匙的SHA1指纹吗?如果您在v1密钥可用时注册了v1密钥,是否确实使用您注册的同一密钥进行签名
此外,根据你的状态栏,你似乎没有得到一个良好的连接。谷歌地图需要网络连接。尝试打开wifi以检查它是否工作。如果是这样,很可能是因为你没有下载地图。如果wifi正常工作,请尝试在关闭wifi的情况下让应用程序运行一段时间,看看地图是否最终通过3G加载。检查下面的示例是否正常工作。。。
check below example it working...
[example link1][1]
[example link2][2]
[example link3][3]
- manifest : Provide all need Permision in This Example i applied Find And Navigation
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demomap1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="com.example.demomap1.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-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.mapv2demo1.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapv2demo1.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<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" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.mapv2demo1.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=" Put Key Here" />
</application>
</manifest>
- Layout xml---I use the com.google.android.gms.maps.SupportMapFragment to show map
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/et_location"
android:layout_alignParentRight="true"
android:text="find" />
<EditText
android:id="@+id/et_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Enter Location"
android:layout_toLeftOf="@id/btn_find" />
</RelativeLayout>
<fragment
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
- Code to integration Map v2 in code the Intent is call the map app which install in phone..
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends FragmentActivity implements OnClickListener {
GoogleMap mapView;
LatLng latLong;
MarkerOptions markerOption;
Button btnFind;
EditText etLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapview)).getMap();
btnFind=(Button)findViewById(R.id.btn_find);
etLocation=(EditText)findViewById(R.id.et_location);
btnFind.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String destination=etLocation.getText().toString();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr="
+ destination));
startActivity(intent);
}
}
[1]: http://karnshah8890.blogspot.in/2013/02/google-maps-android-api-v2.html
[2]: http://android-er.blogspot.in/2012/12/a-simple-example-using-google-maps.html
[3]: http://wptrafficanalyzer.in/blog/showing-current-location-in-google-maps-using-api-v2-with-supportmapfragment/
[示例链接1][1]
[示例链接2][2]
[示例链接3][3]
-清单:在这个示例中,我应用了查找和导航,提供了所有需要的权限
-布局xml——我使用com.google.android.gms.maps.SupportMapFragment来显示地图
-代码中集成地图v2的目的是调用安装在手机中的地图应用程序。。
导入android.content.Intent;
导入android.net.Uri;
导入android.os.Bundle;
导入android.support.v4.app.FragmentActivity;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.SupportMapFragment;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.MarkerOptions;
公共类MainActivity扩展FragmentActivity实现OnClickListener{
谷歌地图地图视图;
LatLng-latLong;
标记选项标记选项;
按钮btnFind;
编辑文本定位;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView=((SupportMapFragment)getSupportFragmentManager().findFragmentById(
R.id.mapview)).getMap();
btnFind=(按钮)findviewbyd(R.id.btn\u find);
etLocation=(EditText)findViewById(R.id.et_位置);
btnFind.setOnClickListener(这个);
}
@凌驾
公共void onClick(视图v){
String destination=etLocation.getText().toString();
意向意向=新意向(android.content.Intent.ACTION\u视图,
解析http://maps.google.com/maps?daddr="
+目的地);
星触觉(意向);
}
}
[1]: http://karnshah8890.blogspot.in/2013/02/google-maps-android-api-v2.html
[2]: http://android-er.blogspot.in/2012/12/a-simple-example-using-google-maps.html
[3]: http://wptrafficanalyzer.in/blog/showing-current-location-in-google-maps-using-api-v2-with-supportmapfragment/
检查下面的示例,它正在工作。。。
[示例链接1][1]
[示例链接2][2]
[示例链接3][3]
-清单:在这个示例中,我应用了查找和导航,提供了所有需要的权限
-布局xml——我使用com.google.android.gms.maps.SupportMapFragment来显示地图
-代码中集成地图v2的目的是调用安装在手机中的地图应用程序。。
导入android.content.Intent;
导入android.net.Uri;
导入android.os.Bundle;
导入android.support.v4.app.FragmentActivity;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
导入com.google.android。