Exemplo n.º 1
0
        public Location getLocation(Geo g)
        {
            try
            {
                string request = "http://maps.google.com/maps/api/geocode/xml?";
                request += "address=" + g.getAddress() + "&" + "sensor=" + g.getSensor();

                //read in xml
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(request);

                XmlNode node = xdoc.DocumentElement;
                XmlNodeList nodeLongAddrCol = node.SelectNodes("//formatted_address");

                Location loc = new Location();

                loc.setDisplay_address(nodeLongAddrCol.Item(0).InnerText);
                string lat = node.SelectNodes("//location/lat").Item(0).InnerText;
                string lng = node.SelectNodes("//location/lng").Item(0).InnerText;
                loc.setCoords(lat + "," + lng);
                loc.setLat(Convert.ToDouble(lat));
                loc.setLng(Convert.ToDouble(lng));
                return loc;
            }
            catch (NullReferenceException)
            {
                return null;
            }
        }
Exemplo n.º 2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (!(tbLoc.Text.Equals("Enter Location")) && !(tbDest.Text.Equals("Enter Destination")))
            {
                mu = new Mapping.MapUtils();

                //get current location
                Mapping.Geo g = new Mapping.Geo();
                gu = new Mapping.GeoUtils();
                g.setAddress(tbLoc.Text);
                startLoc = gu.getLocation(g);
                if (startLoc == null)
                {
                    MessageBox.Show("No matches found for current location.");
                }
                else
                {
                    startLoc.setReady(1);

                    //get intended destination
                    g.setAddress(tbDest.Text);
                    destLoc = gu.getLocation(g);
                    if (destLoc == null)
                    {
                        MessageBox.Show("No matches found for destination.");
                    }
                    else
                    {
                        destLoc.setReady(1);

                        //get avg map centre
                        string avgLoc = gu.getAvgLoc(startLoc.getLat() + destLoc.getLat(), startLoc.getLng() + destLoc.getLng());

                        //update display map
                        //clear previous markers from the array
                        currMap.clearMarkers();
                        //add the new loc markers to the map
                        currMarker = new Mapping.Marker(1, "yellow", "D", destLoc.getCoords());
                        currMap.setMarkers(currMarker.toString());
                        currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords());
                        currMap.setMarkers(currMarker.toString());
                        currMap.setCenter(avgLoc);

                        //generate map
                        pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
                        pictureBox1.Refresh();

                        //update current centre
                        currCentre.setCoords(avgLoc);
                        currCentre.setLat((startLoc.getLat() + destLoc.getLat()) / 2);
                        currCentre.setLng((startLoc.getLng() + destLoc.getLng()) / 2);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void MapTest_Load(object sender, EventArgs e)
        {
            tbDest.Text          = "Enter Destination";
            tbLoc.Text           = "Enter Location";
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            p          = new Point();
            currMap    = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu         = new Mapping.MapUtils();
            gu         = new Mapping.GeoUtils();
            g          = new Mapping.Geo();
            //check phone radio is on.
            if (SystemState.PhoneRadioOff == false)
            {
                Cell.CellUtils cu = new Cell.CellUtils();
                Cell.CellTower ct = cu.getTowerInfo();
                g.setLatLng(cu.getCoords(ct));
                g.setLat(cu.getLat());
                g.setLng(cu.getLng());
                currCentre = gu.getGeoLocation(g);
                currMarker = new Mapping.Marker(1, "red", "S", currCentre.getCoords());
                //update location textbox
                tbLoc.Text = currCentre.getDisplay_address();
            }
            else
            {
                g.setAddress("ANU");
                currCentre = gu.getLocation(g);
            }

            //initialize map settings
            startLoc = new Mapping.Location();
            destLoc  = new Mapping.Location();


            currMap.setMapType("rmap");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            //currMarker = new Mapping.Marker(1, "red", "S", currCentre.getCoords());
            currMap.clearMarkers();
            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));

            //add start location
            startLoc = new Mapping.Location();
            startLoc.setReady(1);
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());

            //tbLoc.Text = currCentre.getDisplay_address();
        }
Exemplo n.º 4
0
        private void setLocCI_Click(object sender, EventArgs e)
        {
            pt = new Point();
            pt = pictureBox1.PointToClient(p);
            gu = new Mapping.GeoUtils();
            mu = new Mapping.MapUtils();

            //translate pixels tapped on to GPS coordinates
            double lat    = currCentre.getLat();
            double lng    = currCentre.getLng();
            double newLat = Mapping.CoordTranslate.adjustLatByPixels(lat, pt.Y - 150, zoom);
            double newLng = Mapping.CoordTranslate.adjustLonByPixels(lng, pt.X - 240, zoom);

            //clear previous markers from the array
            currMap.clearMarkers();

            //add the new loc marker to the map
            currMarker = new Mapping.Marker(1, "red", "S", (newLat + "," + newLng));
            currMap.setMarkers(currMarker.toString());

            //check if need to add existing destination marker
            if (destLoc.getReady() == 1)
            {
                currMarker = new Mapping.Marker(1, "yellow", "D", destLoc.getCoords());
                currMap.setMarkers(currMarker.toString());
            }

            //generate map
            currMap.setCenter((newLat + "," + newLng));
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
            pictureBox1.Refresh();

            //update start location object
            startLoc.setLat(newLat);
            startLoc.setLng(newLng);
            startLoc.setCoords((newLat + "," + newLng));
            startLoc.setReady(1);

            //update centre location
            currCentre.setLat(newLat);
            currCentre.setLng(newLng);
            currCentre.setCoords((newLat + "," + newLng));

            //update address to textbox
            Mapping.Geo tempG = new Mapping.Geo();
            tempG.setLat(newLat);
            tempG.setLatLng((newLat + "," + newLng));
            Mapping.Location tempLoc = gu.getGeoLocation(tempG);
            tbLoc.Text = tempLoc.getDisplay_address();
        }
Exemplo n.º 5
0
        private void miGetCellLoc_Click(object sender, EventArgs e)
        {
            p          = new Point();
            currMap    = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu         = new Mapping.MapUtils();
            gu         = new Mapping.GeoUtils();
            g          = new Mapping.Geo();

            Cell.CellUtils cu = new Cell.CellUtils();
            Cell.CellTower ct = cu.getTowerInfo();
            g.setLatLng(cu.getCoords(ct));
            g.setLat(cu.getLat());
            g.setLng(cu.getLng());
            currCentre = gu.getGeoLocation(g);

            //update start location object
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());
            startLoc.setDisplay_address(currCentre.getDisplay_address());
            startLoc.setReady(1);

            currMap.setMapType("hyb");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            currMap.clearMarkers();
            currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords());

            if (destLoc.getReady() == 1)
            {
                currMarker = new Mapping.Marker(1, "yellow", "D", destLoc.getCoords());
            }

            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
            pictureBox1.Refresh();

            //update location textbox
            tbLoc.Text = startLoc.getDisplay_address();
        }
Exemplo n.º 6
0
        private void genMap(double lat, double lng)
        {
            p          = new Point();
            currMap    = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu         = new Mapping.MapUtils();
            gu         = new Mapping.GeoUtils();
            g          = new Mapping.Geo();

            g.setLatLng(lat + "," + lng);
            g.setLat(lat);
            g.setLng(lng);
            currCentre = gu.getGeoLocation(g);

            //update start location object
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());
            startLoc.setDisplay_address(currCentre.getDisplay_address());
            startLoc.setReady(1);

            currMap.setMapType("hyb");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            currMap.clearMarkers();
            currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords());

            if (destLoc.getReady() == 1)
            {
                currMarker = new Mapping.Marker(1, "yellow", "D", startLoc.getCoords());
            }

            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
            pictureBox1.Refresh();

            //update location textbox
            tbLoc.Text = startLoc.getDisplay_address();
        }
Exemplo n.º 7
0
        public Location getGeoLocation(Geo g)
        {
            //http://maps.google.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false
            string request = "http://maps.google.com/maps/api/geocode/xml?";
            request += "latlng=" + g.getLatLng() + "&" + "sensor=" + g.getSensor();

            //read in xml
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(request);

            XmlNode node = xdoc.DocumentElement;
            XmlNodeList nodeLongAddrCol = node.SelectNodes("//formatted_address");

            XmlNodeList nodeShortAddrCol = node.SelectNodes("/GeocodeResponse/address_component[type=route]");
            Location loc = new Location();
            loc.setDisplay_address(nodeLongAddrCol.Item(0).InnerText);

            double lat = g.getLat();
            double lng = g.getLng();
            loc.setCoords(lat + "," + lng);
            loc.setLat(lat);
            loc.setLng(lng);
            return loc;
        }
Exemplo n.º 8
0
        private void setLocCI_Click(object sender, EventArgs e)
        {
            pt = new Point();
            pt = pictureBox1.PointToClient(p);
            gu = new Mapping.GeoUtils();
            mu = new Mapping.MapUtils();

            //translate pixels tapped on to GPS coordinates
            double lat = currCentre.getLat();
            double lng = currCentre.getLng();
            double newLat = Mapping.CoordTranslate.adjustLatByPixels(lat, pt.Y - 150, zoom);
            double newLng = Mapping.CoordTranslate.adjustLonByPixels(lng, pt.X - 240, zoom);

            //clear previous markers from the array
            currMap.clearMarkers();

            //add the new loc marker to the map
            currMarker = new Mapping.Marker(1, "red", "S", (newLat + "," + newLng));
            currMap.setMarkers(currMarker.toString());

            //check if need to add existing destination marker
            if (destLoc.getReady() == 1)
            {
                currMarker = new Mapping.Marker(1, "yellow", "D", destLoc.getCoords());
                currMap.setMarkers(currMarker.toString());
            }

            //generate map
            currMap.setCenter((newLat + "," + newLng));
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
            pictureBox1.Refresh();

            //update start location object
            startLoc.setLat(newLat);
            startLoc.setLng(newLng);
            startLoc.setCoords((newLat + "," + newLng));
            startLoc.setReady(1);

            //update centre location
            currCentre.setLat(newLat);
            currCentre.setLng(newLng);
            currCentre.setCoords((newLat + "," + newLng));

            //update address to textbox
            Mapping.Geo tempG = new Mapping.Geo();
            tempG.setLat(newLat);
            tempG.setLatLng((newLat + "," + newLng));
            Mapping.Location tempLoc = gu.getGeoLocation(tempG);
            tbLoc.Text = tempLoc.getDisplay_address();
        }
Exemplo n.º 9
0
        private void miGetCellLoc_Click(object sender, EventArgs e)
        {
            p = new Point();
            currMap = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu = new Mapping.MapUtils();
            gu = new Mapping.GeoUtils();
            g = new Mapping.Geo();

            Cell.CellUtils cu = new Cell.CellUtils();
            Cell.CellTower ct = cu.getTowerInfo();
            g.setLatLng(cu.getCoords(ct));
            g.setLat(cu.getLat());
            g.setLng(cu.getLng());
            currCentre = gu.getGeoLocation(g);

            //update start location object
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());
            startLoc.setDisplay_address(currCentre.getDisplay_address());
            startLoc.setReady(1);

            currMap.setMapType("hyb");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            currMap.clearMarkers();
            currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords());

            if (destLoc.getReady() == 1)
            {
                currMarker = new Mapping.Marker(1, "yellow", "D", destLoc.getCoords());
            }

            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
            pictureBox1.Refresh();

            //update location textbox
            tbLoc.Text = startLoc.getDisplay_address();
        }
Exemplo n.º 10
0
        private void MapTest_Load(object sender, EventArgs e)
        {
            tbDest.Text = "Enter Destination";
            tbLoc.Text = "Enter Location";
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            p = new Point();
            currMap = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu = new Mapping.MapUtils();
            gu = new Mapping.GeoUtils();
            g = new Mapping.Geo();
            //check phone radio is on.
            if (SystemState.PhoneRadioOff == false)
            {
                Cell.CellUtils cu = new Cell.CellUtils();
                Cell.CellTower ct = cu.getTowerInfo();
                g.setLatLng(cu.getCoords(ct));
                g.setLat(cu.getLat());
                g.setLng(cu.getLng());
                currCentre = gu.getGeoLocation(g);
                currMarker = new Mapping.Marker(1, "red", "S", currCentre.getCoords());
                //update location textbox
                tbLoc.Text = currCentre.getDisplay_address();
            }
            else
            {
                g.setAddress("ANU");
                currCentre = gu.getLocation(g);
            }

            //initialize map settings
            startLoc = new Mapping.Location();
            destLoc = new Mapping.Location();

            currMap.setMapType("rmap");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            //currMarker = new Mapping.Marker(1, "red", "S", currCentre.getCoords());
            currMap.clearMarkers();
            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));

            //add start location
            startLoc = new Mapping.Location();
            startLoc.setReady(1);
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());

            //tbLoc.Text = currCentre.getDisplay_address();
        }
Exemplo n.º 11
0
        private void genMap(double lat, double lng)
        {
            p = new Point();
            currMap = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu = new Mapping.MapUtils();
            gu = new Mapping.GeoUtils();
            g = new Mapping.Geo();

            g.setLatLng(lat + "," + lng);
            g.setLat(lat);
            g.setLng(lng);
            currCentre = gu.getGeoLocation(g);

            //update start location object
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());
            startLoc.setDisplay_address(currCentre.getDisplay_address());
            startLoc.setReady(1);

            currMap.setMapType("hyb");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            currMap.clearMarkers();
            currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords());

            if (destLoc.getReady() == 1)
            {
                currMarker = new Mapping.Marker(1, "yellow", "D", startLoc.getCoords());
            }

            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
            pictureBox1.Refresh();

            //update location textbox
            tbLoc.Text = startLoc.getDisplay_address();
        }
Exemplo n.º 12
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if ( !(tbLoc.Text.Equals("Enter Location")) && !(tbDest.Text.Equals("Enter Destination")) )
            {
                mu = new Mapping.MapUtils();

                //get current location
                Mapping.Geo g = new Mapping.Geo();
                gu = new Mapping.GeoUtils();
                g.setAddress(tbLoc.Text);
                startLoc = gu.getLocation(g);
                if (startLoc == null)
                {
                    MessageBox.Show("No matches found for current location.");
                }
                else
                {
                    startLoc.setReady(1);

                    //get intended destination
                    g.setAddress(tbDest.Text);
                    destLoc = gu.getLocation(g);
                    if (destLoc == null)
                    {
                        MessageBox.Show("No matches found for destination.");
                    }
                    else
                    {
                        destLoc.setReady(1);

                        //get avg map centre
                        string avgLoc = gu.getAvgLoc(startLoc.getLat() + destLoc.getLat(), startLoc.getLng() + destLoc.getLng());

                        //update display map
                        //clear previous markers from the array
                        currMap.clearMarkers();
                        //add the new loc markers to the map
                        currMarker = new Mapping.Marker(1, "yellow", "D", destLoc.getCoords());
                        currMap.setMarkers(currMarker.toString());
                        currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords());
                        currMap.setMarkers(currMarker.toString());
                        currMap.setCenter(avgLoc);

                        //generate map
                        pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
                        pictureBox1.Refresh();

                        //update current centre
                        currCentre.setCoords(avgLoc);
                        currCentre.setLat((startLoc.getLat() + destLoc.getLat()) / 2);
                        currCentre.setLng((startLoc.getLng() + destLoc.getLng()) / 2);
                    }

                }
            }
        }