- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用处理程序从支持 map fragment 中获取 GoogleMap。我真的迷路了,几天来一直在努力修复它。 map 加载正常,但我怀疑它返回的是空值。我知道可能有一些不好的做法,但这不是我的问题。我尝试使用 AsyncTask 和 Handler。我在各种移动设备上测试过,没有使用模拟器。这是我的代码,我删除了一些其他导入,但它们在那里(显然不是整个程序):
import com.codexmalta.mytravelbuddy.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class Itinerary extends FragmentActivity implements View.OnClickListener {
//Google Map
GoogleMap map;
byte choice;
protected ProgressDialog dialog;
CameraPosition cameraPosition;
Timer timer = new Timer();
LinearLayout[] l = new LinearLayout[10];
TextView[] time = new TextView[10];
TextView[] desc = new TextView[10];
TextView[] loc = new TextView[10];
double[] lat = new double[10];
double[] lng = new double[10];
MarkerOptions[] marker = new MarkerOptions[10];
//Get Itinerary
GetItinerary gi = new GetItinerary();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting_point);
choice = getIntent().getByteExtra("choice", choice);
//Methods
getMapFragment();
getLayouts();
getFields();
gi.main(choice);
fillFields();
removeExtraLayouts(gi.giveNumDay1(),gi.giveNumDay2());
getMap();
displayMarkers();
animateCamera();
}
SupportMapFragment fm = new SupportMapFragment();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.starting_point, menu);
return true;
}
private void removeExtraMarkers(){
for(int i = 0; i < 10; i++){
if(lat[i] == 0 && lng[i] == 0){
marker[i].alpha(0);
}
}
}
private void displayMarkers(){
String[] s = new String[10];
for(int i = 0; i < 10; i++){
s[i] = (String) loc[i].getText();
map.addMarker(marker[i].position(new LatLng(lat[i], lng[1])).title(s[i])).setVisible(true);
}
}
public void getMapFragment(){
fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
}
Handler mHandler = new Handler();
public void getMap(){
mHandler.post(new Runnable() {
@Override
public void run() {
GoogleMap map = fm.getMap();
if (map != null) {
map.setMyLocationEnabled(true);
// INIT HERE
map.getUiSettings().setMyLocationButtonEnabled(false);
// ...
} else mHandler.post(this);
}
});
while(map == null){
map = fm.getMap();
if(map!= null)break;
}
}
private void removeExtraLayouts(int a, int b){
//Day One
switch(a){
case 5:
l[0].removeAllViews();
l[1].removeAllViews();
l[2].removeAllViews();
l[3].removeAllViews();
l[4].removeAllViews();
break;
case 4:
l[1].removeAllViews();
l[2].removeAllViews();
l[3].removeAllViews();
l[4].removeAllViews();
break;
case 3:
l[2].removeAllViews();
l[3].removeAllViews();
l[4].removeAllViews();
break;
case 2:
l[3].removeAllViews();
l[4].removeAllViews();
break;
case 1:
l[4].removeAllViews();
break;
}
//Day Two
switch(b){
case 5:
l[5].removeAllViews();
l[6].removeAllViews();
l[7].removeAllViews();
l[8].removeAllViews();
l[9].removeAllViews();
break;
case 4:
l[6].removeAllViews();
l[7].removeAllViews();
l[8].removeAllViews();
l[9].removeAllViews();
break;
case 3:
l[7].removeAllViews();
l[8].removeAllViews();
l[9].removeAllViews();
break;
case 2:
l[8].removeAllViews();
l[9].removeAllViews();
break;
case 1:
l[9].removeAllViews();
break;
}
}
private void getLayouts(){
l[0] = (LinearLayout)findViewById(R.id.a1);
l[0].setOnClickListener(this);
l[1] = (LinearLayout)findViewById(R.id.a2);
l[1].setOnClickListener(this);
l[2] = (LinearLayout)findViewById(R.id.a3);
l[2].setOnClickListener(this);
l[3] = (LinearLayout)findViewById(R.id.a4);
l[3].setOnClickListener(this);
l[4] = (LinearLayout)findViewById(R.id.a5);
l[4].setOnClickListener(this);
l[5] = (LinearLayout)findViewById(R.id.a6);
l[5].setOnClickListener(this);
l[6] = (LinearLayout)findViewById(R.id.a7);
l[6].setOnClickListener(this);
l[7] = (LinearLayout)findViewById(R.id.a8);
l[7].setOnClickListener(this);
l[8] = (LinearLayout)findViewById(R.id.a9);
l[8].setOnClickListener(this);
l[9] = (LinearLayout)findViewById(R.id.a10);
l[9].setOnClickListener(this);
}
private void getFields(){
time[0] = (TextView)findViewById(R.id.time1);
desc[0] = (TextView)findViewById(R.id.desc1);
loc[0] = (TextView)findViewById(R.id.loc1);
time[1] = (TextView)findViewById(R.id.time2);
desc[1] = (TextView)findViewById(R.id.desc2);
loc[1] = (TextView)findViewById(R.id.loc2);
time[2] = (TextView)findViewById(R.id.time3);
desc[2] = (TextView)findViewById(R.id.desc3);
loc[2] = (TextView)findViewById(R.id.loc3);
time[3] = (TextView)findViewById(R.id.time4);
desc[3] = (TextView)findViewById(R.id.desc4);
loc[3] = (TextView)findViewById(R.id.loc4);
time[4] = (TextView)findViewById(R.id.time5);
desc[4] = (TextView)findViewById(R.id.desc5);
loc[4] = (TextView)findViewById(R.id.loc5);
time[5] = (TextView)findViewById(R.id.time6);
desc[5] = (TextView)findViewById(R.id.desc6);
loc[5] = (TextView)findViewById(R.id.loc6);
time[6] = (TextView)findViewById(R.id.time7);
desc[6] = (TextView)findViewById(R.id.desc7);
loc[6] = (TextView)findViewById(R.id.loc7);
time[7] = (TextView)findViewById(R.id.time8);
desc[7] = (TextView)findViewById(R.id.desc8);
loc[7] = (TextView)findViewById(R.id.loc8);
time[8] = (TextView)findViewById(R.id.time9);
desc[8] = (TextView)findViewById(R.id.desc9);
loc[8] = (TextView)findViewById(R.id.loc9);
time[9] = (TextView)findViewById(R.id.time10);
desc[9] = (TextView)findViewById(R.id.desc10);
loc[9] = (TextView)findViewById(R.id.loc10);
}
private void fillFields(){
for(int i = 0; i < 10; i++){
time[i].setText(gi.giveTimeArray(i));
desc[i].setText(gi.giveDescriptionArray(i));
loc[i].setText(gi.giveLocationArray(i));
lat[i] = gi.giveLatitudeArray(i);
lng[i] = gi.giveLongitudeArray(i);
}
}
private void animateCamera(){
CameraPosition.builder().target(new LatLng(20, 20)).zoom(12).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.a1:
//animateCamera(lat[0],lng[0]);
break;
case R.id.a2:
//animateCamera(lat[1],lng[1]);
break;
case R.id.a3:
//animateCamera(lat[2],lng[2]);
break;
case R.id.a4:
//animateCamera(lat[3],lng[3]);
break;
case R.id.a5:
//animateCamera(lat[4],lng[4]);
break;
case R.id.a6:
//animateCamera(lat[5],lng[5]);
break;
case R.id.a7:
//animateCamera(lat[6],lng[6]);
break;
case R.id.a8:
//animateCamera(lat[7],lng[7]);
break;
case R.id.a9:
//animateCamera(lat[8],lng[8]);
break;
case R.id.a10:
//animateCamera(lat[9],lng[9]);
break;
}
}
}
这是我的 list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codexmalta.mytravelbuddy"
android:versionCode="1"
android:versionName="0.5" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/tb02"
android:label="Travel Buddy"
android:configChanges = "keyboardHidden|orientation"
>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.codexmalta.mytravelbuddy.MainActivity"
android:label="Travel Buddy"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.codexmalta.mytravelbuddy.Itinerary"
android:label="Itinerary"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait">
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
</manifest>
这是我在布局 xml 中保存 map 的 fragment :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:layout_marginEnd="0dp"
android:layout_marginTop="-20dp"
android:background="@drawable/background"
android:measureAllChildren="false"
android:minHeight="75dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Itinerary" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
任何帮助将不胜感激,因为我刚刚碰壁。我搜索了其他问题,但没有一个有效/或者我不明白它们是如何工作的。
最佳答案
我完全不明白你为什么要在处理程序中这样做。这个:
GoogleMap gmap = ((SupportMapFragment).getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
放入 onCreate()
方法将返回 GoogleMap 对象。
关于java - getMap() 方法可能返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20742078/
我有两个方法@GetMapping和@GetMapping("/{id}") @RestController("/user"){ public class UserRestController { @
我想将编码添加到映射 Controller 的响应中。但是由于某种原因出现了编译错误。只需要一个值数组 如何在响应中添加编码? 最佳答案 @GetMapping("/cards", produces
有时可能会发生这样的情况:数据库中什么都没有,方法 .findAll() 没有任何内容可显示并返回空主体。我知道我有这个函数的返回类型“List”,并且我不能直接返回字符串,但是如果列表为空,我如何以
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 7 年前。 我知道周围有很多类似的帖子,但没
我正在尝试为 @GetMapping 创建多条路线。例如,localhost:8080/tasks 和 localhost:8080/tasks/?status=... 所以我创建了如下几个方法。 C
Image for clarification我是 Spring MVC 的新手,我正在 Maven 上做这个项目。我试图导入 @GetMapping 但它没有被导入。可能是什么问题?有人可以帮我吗?
我只是创建一个 map 项目并执行此代码。但是有 getMap() 错误。我尝试了一些来自互联网的示例代码,但 getMap() 函数中也存在同样的错误。代码是: private Google
private GoogleMap mMap; 我从 MainActivity 开始一个类似的 Activity : @SuppressWarnings("StatementWithEmptyBody
我正在尝试使用堆栈溢出答案之一的交互式信息窗口。 链接如下: interactive infowindow 但是我在代码中使用 getMap() 时遇到错误。虽然我尝试使用 getMapAsync 但
我试图在不依赖 application.properties 中的 server.contextPath 的情况下创建我的路由 这是一个例子: @PreAuthorize("hasRole('ROLE
这个问题在这里已经有了答案: Cannot resolve method getMap() (2 个答案) 关闭 4 年前。 我对这段代码有疑问,“无法解析方法 getMap()。我没有找到问题出在
我正在尝试让一个 map fragment 在我的应用程序中工作,但在尝试获取我的 GoogleMap 对象时仍然出现错误。 FragmentWithMap.java import android.M
将 Leaflet 添加到我的 AngularJS 应用程序后: 并进行设置: // Initialise the feature group to store editable layers va
在我的 Controller 中,@GetMapping 的以下使用有效: @GetMapping(value = "/new") public String newEssay(){ retu
我有以下 Controller : @RestController @RequestMapping("/api/{brand}") public class CarController { pri
我使用处理程序从支持 map fragment 中获取 GoogleMap。我真的迷路了,几天来一直在努力修复它。 map 加载正常,但我怀疑它返回的是空值。我知道可能有一些不好的做法,但这不是我的问
我在 Spring boot 中遇到了 @GetMapping 的问题。 关于我的 @GetMapping 函数,在从数据库中获取所有数据时,它没有在此模型上序列化我的 id: //User.java
在尝试创建 GoogleMap 对象(它返回 null)时,我在让 .getMap() 工作时遇到了很多麻烦,我环顾四周,发现人们也遇到了类似的问题,但无法从他们那里找到任何帮助。在当前的实现中,我如
在尝试了几乎所有方法之后,我似乎无法在不提取空对象引用的情况下获取 map 。我试图将一个 google mapfragment 膨胀成一个 fragment ,但是每次我这样做时我总是保留一个 ge
这个问题在这里已经有了答案: Cannot resolve method getMap() (2 个答案) 关闭 4 年前。 我有一个在手机上运行良好的 GPS 应用程序。但是,我看到有人在生产中出
我是一名优秀的程序员,十分优秀!