Android的地图应用程序跟踪误差 [英] android Map Application Trace Error

查看:183
本文介绍了Android的地图应用程序跟踪误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款Android地图应用上放置map.I标记正在使用JSON解析URL,从标记数据放置在地图上,但我得到了以下错误在日志Cat.Here是登录猫

I am developing a android map application to place markers on map.I am Using JSON to Parse the markers data from url to Place On Map But I got The Following Error in Log Cat.Here is Log Cat

    07-16 11:27:37.771: E/Trace(32163): error opening trace file: No such file or directory (2)
07-16 11:27:37.791: W/dalvikvm(32163): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:27:38.391: W/System.err(32163): Invalid int: ""
07-16 11:27:38.411: W/dalvikvm(32163): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:27:39.961: W/dalvikvm(32163): threadid=1: thread exiting with uncaught exception (group=0x41cdc438)
07-16 11:28:48.851: E/Trace(32327): error opening trace file: No such file or directory (2)
07-16 11:28:48.901: W/dalvikvm(32327): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:28:49.271: W/System.err(32327): Invalid int: ""
07-16 11:28:49.291: W/dalvikvm(32327): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:28:49.871: W/dalvikvm(32327): threadid=1: thread exiting with uncaught exception (group=0x41cdc438)

源代码
这里是我的资料来源$ C ​​$ C

Source Here is My Source Code

    package pkg.pkg.map3;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;

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;

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment; 

import android.graphics.drawable.Drawable;
import android.net.ParseException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;



public class MainActivity extends FragmentActivity  {
    JSONArray jArray;
    String result = null;
    InputStream is = null;
    StringBuilder sb=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //GoogleMap mMap;
        //mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
        GoogleMap mMap = fm.getMap();
        String readTwitterFeed = readpoints();
        double LAT;
        double LANG;
        String INFO; 
        try {
              JSONArray jsonArray = new JSONArray(readTwitterFeed);
              for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                LAT=jsonObject.getDouble("lat");
                LANG=jsonObject.getDouble("lang");
                INFO=jsonObject.getString("info");
                mMap.addMarker(new MarkerOptions().position(new LatLng(LAT, LANG)).title(INFO));
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    public String readpoints() {
        StringBuilder builder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("http://202.125.144.34/a/map.php");
        try {
          HttpResponse response = client.execute(httpGet);
          StatusLine statusLine = response.getStatusLine();
          int statusCode = statusLine.getStatusCode();
          if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            builder.append(reader.readLine() + "\n");
            String line;
            while ((line = reader.readLine()) != null) {
              builder.append(line + "\n");
            }
          } else {
            Log.e(MainActivity.class.toString(), "Failed to download file");
          }
        } catch (ClientProtocolException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        return builder.toString();
      }
}

清单

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

    <uses-sdk android:minSdkVersion="10" android:maxSdkVersion="16" android:targetSdkVersion="16"/>

    <permission
        android:name="pkg.pkg.map3.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

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


    <uses-permission android:name="pkg.pkg.map3.maps.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" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_PERMISSION"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:debuggable="true" >
        <activity
            android:name="pkg.pkg.map3.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="AIzaSyDhJFrxxmuDGC4EC389AJ9AmyKFc--0S8s" />
    </application>

</manifest>

布局

<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"
    tools:context=".MainActivity" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

任何一个可以告诉我怎么可能是问题关于这Problem.Plz帮助!

Any One Tell me What May Be The Issue Regarding This Problem.Plz Help !

推荐答案

添加这体现

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

更改为以下

    <uses-permission android:name="pkg.pkg.map3.maps.permission.MAPS_RECEIVE" />

从我看到你的分SDK是8。

From what i see your min sdk is 8.

您应该使用 SupportMapFragment

<一个href=\"https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/SupportMapFragment\" rel=\"nofollow\">https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/SupportMapFragment

<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"  
android:layout_width="match_parent"
android:layout_height="match_parent"/>

您活动必须延长 FragmentActivity 并初始化GoogleMap对象使用下面的。

Your activity must extend FragmentActivity and to initialize GoogleMap object use the below.

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap(); 

另外,还要确保您导入下面的

Also make sure you imported the below

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment; 

此外,我看你是不是全光照的AsyncTask 线程为相关元网络运行

HttpResponse response = client.execute(httpGet);

您将获得 NetWorkOnMainThreadException 如果您在后蜂窝版本中运行上面的。

You will get NetWorkOnMainThreadException if you run the above on post honeycomb versions.

这篇关于Android的地图应用程序跟踪误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆