资源简介

该代码实现了对 googlemap网站的查询返回的包含POI信息的文本内容解析功能,可以提取创poi的名称,地址,电话,经纬度等信息。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoogleParse
{

    public class googlepoi {
        public string oid = ““;
        public string classaddress = ““;
        public string address = ““;
        public string fname = ““;
        public string name = ““;
        public string category = ““;
        public string phone = ““;
        public string website = ““;
        public string lat = ““;
        public string lon = ““;

    }
    public class pairs
    {
        public int p1 = -1 p2 = -1;
        public pairs(int _p1 int _p2)
        {
            this.p1 = _p1; this.p2 = _p2;
        }
    }

    public class googlepoi_parser
    {
       
        public googlepoi_parser() { }
       static public List GetItems(string str) {

            List pois = new List();
            pairs p = getparis(str “{“ “}“ 0);
            // Console.WriteLine(p.p1+““+p.p2);
            string mstr = str.Substring(p.p1 p.p2 - p.p1 + 1);
            int pos = getpos(str “[“ p.p2 3);
            p = getparis(str “[“ “]“ pos);
            string itemstr = ““;
            //获取数据列表的内容
            mstr = str.Substring(p.p1 p.p2 - p.p1 + 1);
            pos = 1;
            do
            {
                p = getparis(mstr “[“ “]“ pos);

                itemstr = mstr.Substring(p.p1 p.p2 - p.p1 + 1);
               // Console.WriteLine(itemstr);
                googlepoi poi= parseItem(itemstr);
                if (poi != null) pois.Add(poi);
                pos = getpos(mstr “[“ p.p2 1);
                             
                if (pos == -1) break;

            } while (true);
            return pois;
        }

        /// 
        /// 解析一个poi的内容   //实体id,分级地址,全地址,带地址名称,名称,类型,联系电话,联系网站,经纬度,
        /// 

        /// 
        static googlepoi parseItem(string itemstr)
        {
            googlepoi poi = null;
            int pos = getpos(itemstr “[“ 1 1);
            pairs p = getparis(itemstr “[“ “]“ pos);

            List items = new List();

            //XXXXXXXXX
            string mstr = itemstr.Substring(p.p1 + 1 p.p2 - p.p1 - 1);
            int p0 = 0;
            int gap = 1;
            do
            {

                if (mstr.Substring(p0 1) == “[“)
                {
                    p = getparis(mstr “[“ “]“ p0);
                    pos = getpos(mstr ““ p.p2 1);
                    gap = 1;
                }
                else if (mstr.Substring(p0).StartsWith(“\\\““))
                {
                    pos = getpos(mstr “\\\““ p0 1);
                    gap = 3;
                }
                else {
                    pos = getpos(mstr ““ p0 1);
                    gap = 1;
                }
             

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-02-01 11:12  googlepoiparse\
     目录           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\
     目录           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\.vs\
     目录           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\.vs\ConsoleApplication1\
     目录           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\.vs\ConsoleApplication1\v14\
     文件       42496  2016-02-01 11:25  googlepoiparse\ConsoleApplication1\.vs\ConsoleApplication1\v14\.suo
     目录           0  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\
     文件        1024  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1.sln
     文件         189  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\App.config
     目录           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\
     目录           0  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\
     文件       25350  2016-01-31 00:49  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\china.txt
     文件        8192  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
     文件         189  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe.config
     文件       19968  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.pdb
     文件       22696  2016-02-01 11:13  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe
     文件         189  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.config
     文件         490  2014-01-14 13:31  googlepoiparse\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.manifest
     文件       25350  2016-01-31 00:49  googlepoiparse\ConsoleApplication1\ConsoleApplication1\china.txt
     文件        2745  2016-02-01 10:26  googlepoiparse\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.csproj
     文件        9367  2016-02-01 11:10  googlepoiparse\ConsoleApplication1\ConsoleApplication1\googlepoi_parser.cs
     目录           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\
     目录           0  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\
     文件         542  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\ConsoleApplication1.csproj.FileListAbsolute.txt
     文件        8192  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\ConsoleApplication1.exe
     文件       19968  2016-02-01 11:14  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\ConsoleApplication1.pdb
     文件        6842  2016-02-01 10:17  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2016-01-29 11:19  googlepoiparse\ConsoleApplication1\ConsoleApplication1\obj\Debug\TempPE\
............此处省略3个文件信息

评论

共有 条评论