private void MapInfo() { MapInfo mapInfo = new MapInfo(); MarkerPoint myLocation = mapInfo.GetMyLocation(); var xmlMarkers = mapInfo.GetAllExistingMarkers(); mapInfo.InsertNewMarker(myLocation, xmlMarkers, IsDonator()); Location = myLocation; //if (Location != null // && // String.Equals(IsDonator().ToString(), true.ToString(), StringComparison.CurrentCultureIgnoreCase) //) //{ // // The user has allready set a maker and donation status is not changed from that point //} //else //{ // MapInfo mapInfo = new MapInfo(); // MarkerPoint myLocation = mapInfo.GetMyLocation(); // var xmlMarkers = mapInfo.GetAllExistingMarkers(); // mapInfo.InsertNewMarker(myLocation, xmlMarkers, IsDonator()); // Location = myLocation; //} }
private void MapInfo() { MapInfo mapInfo = new MapInfo(); MarkerPoint myLocation = new MarkerPoint(); myLocation = mapInfo.GetMyLocation(); if (myLocation != null) { myLocation.IsDonator = IsDonator(); mapInfo.InsertNewMarker(myLocation); Location = myLocation; } }
public void InsertNewMarker(MarkerPoint markerPoint) { try { var dataString = JsonConvert.SerializeObject(markerPoint); WebClient client = new WebClient { Encoding = Encoding.UTF8 }; client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); Uri uri = new Uri(@"http://www.marlin3DprinterTool.se/MapInfo/MarkerJSON.php"); client.UploadString(uri, "POST", dataString); } catch (Exception e) { } }
public void InsertNewMarker(MarkerPoint markerPoint, XmlDocument xml, bool isDonator) { try { var category = isDonator ? 2 : 1; string sql = "INSERT INTO xvom_wpgmza(map_id,address,description,pic,link,icon,lat,lng,anim,title,infoopen,category,approved,retina,type,did,other_data) " + $"VALUES(1,'{markerPoint.City}','','','','','{markerPoint.Latitude}','{markerPoint.Longitude}',0,'',0,'',{category},0,0,'','')"; string url = @"http://www.marlin3DprinterTool.se/MapInfo/InsertNewMarker.php"; WebClient client = new WebClient { Encoding = Encoding.UTF8 }; client.UploadString(url, sql); } catch (Exception e) { } }
private MarkerPoint GetMyLocation(string lat, string lng, bool isDonator) { string coordinate = $"{lat},{lng}"; XmlDocument xDoc = new XmlDocument(); try { xDoc.Load("https://maps.googleapis.com/maps/api/geocode/xml?latlng=" + coordinate + "&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDfNL99sHWyLZu_Fpwu4-erhQgymdH5EFI"); XmlNodeList xNodelst = xDoc.GetElementsByTagName("result"); XmlNode xNode = xNodelst.Item(0); if (xNode != null) { MarkerPoint marker = new MarkerPoint(); marker.City = GetCity(xNode); marker.CountryName = GetCountry(xNode); marker.Latitude = lat; marker.Longitude = lng; marker.IsDonator = isDonator; return(marker); } } catch (Exception e) { Debug.WriteLine(lat + " " + lng + ":" + e.Message); Thread.Sleep(1000); } return(null); }
public MarkerPoint GetMyLocation() { string myIp = null; XmlDocument xml = new XmlDocument(); try { var url = "http://checkip.dyndns.org"; WebRequest getMyIprRequest = WebRequest.Create(url); WebResponse getMyIpResponse = getMyIprRequest.GetResponse(); StreamReader getMyIpStreamReader = new StreamReader(getMyIpResponse.GetResponseStream()); xml.LoadXml(getMyIpStreamReader.ReadToEnd().Trim()); XmlNode xmlNodeIp = xml.SelectSingleNode(@"/html/body"); if (xmlNodeIp != null) { string currentIp = xmlNodeIp.InnerText; string[] splitData = xmlNodeIp.InnerText.Split(':'); if (splitData.Length == 2) { myIp = splitData[1].Trim(); } } url = $"http://freegeoip.net/xml/{myIp}"; WebRequest getMyLocationRequest = WebRequest.Create(url); WebResponse getMyLocationResponse = getMyLocationRequest.GetResponse(); StreamReader getMyLocationStreamReader = new StreamReader(getMyLocationResponse.GetResponseStream() ?? throw new InvalidOperationException()); xml.LoadXml(getMyLocationStreamReader.ReadToEnd().Trim()); XmlNode xmlNodeLatitude = xml.SelectSingleNode(@"/Response/Latitude"); XmlNode xmlNodeLongitude = xml.SelectSingleNode(@"/Response/Longitude"); MarkerPoint markerPoint = new MarkerPoint(); Updater updater = new Updater(); bool isDonator = updater.IsDonator(); if (xmlNodeLatitude != null && xmlNodeLongitude != null) { markerPoint = GetMyLocation(xmlNodeLatitude.InnerText, xmlNodeLongitude.InnerText, isDonator); return(markerPoint); } return(null); } catch (Exception) { return(null); } }