我想显示活动到现有应用程序的地图。我将地图片段添加到我的xml中并获取api密钥,但应用程序在error以下。我该如何解决?
我通过右键单击活动包添加地图xml和活动,然后选择google maps活动,但同样无法正常工作,并且出现错误。
我的xml:
rs = st.executeQuery("select * from auctions");
System.out.println("### TESTING DATETIMES ####");
while(rs.next()){
Timestamp start = rs.getTimestamp("startdatetime");
Timestamp current = Timestamp.valueOf(LocalDateTime.now().format(formatter));
Timestamp end = rs.getTimestamp("enddatetime");
int auctionID = rs.getInt("aucID");
System.out.println(start);
System.out.println(current);
System.out.println(end);
boolean inactive = current.after(end);
System.out.println(inactive);
if(current.after(end)){
System.out.println("Inactive");
st.executeUpdate("UPDATE auctions SET status='inactive' WHERE aucID=" + auctionID);
}else{
System.out.println("Active");
st.executeUpdate("UPDATE auctions SET status='active' WHERE aucID=" + auctionID);
}
}
我的活动
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:context="com.co.KITIL.MapActivity"/>
<Button
android:id="@+id/saveBtn"
android:layout_width="match_parent"
android:layout_height="55dp"
android:text="شروع کار"
android:textSize="15sp"
android:background="@color/blue"
android:textColor="@android:color/white"/>
</LinearLayout>
AndroidManifest:
package com.co.KITIL;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
public class MapActivity extends FragmentActivity implements OnMapReadyCallback {
SupportMapFragment mapView;
GoogleMap googleMap;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapView=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
}
}
来自debug.res.values的google_maps_api.xml;
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIz-------------------------bcI" />
错误:
<resources>
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AI-----------------bcI</string>