Why does Google Maps containsLocation never find a point inside my polygon? - google-maps

I'm having issues with the following code in that my points never find a point within a polygon using google.maps.geometry.poly.containsLocation. You can see the full code and that there are indeed points in the polygon here http://htinteractive.com/crime_map_fairview.html However in the console you will see that none of the points were found to be in the polygon per the containsLocation function.
I feel like maybe I'm not passing in one the values correctly to the containsLocation function, but so far what I've found in the documentation this seems correct.
var myLatlng = new google.maps.LatLng(lat,lon);
fairview = [
new google.maps.LatLng(39.161536, -86.535107),
new google.maps.LatLng(39.17885, -86.534825),
new google.maps.LatLng(39.179068, -86.547164),
new google.maps.LatLng(39.180989, -86.551803),
new google.maps.LatLng(39.181546, -86.556001),
new google.maps.LatLng(39.170956, -86.569335),
new google.maps.LatLng(39.158487, -86.570365),
new google.maps.LatLng(39.161482, -86.566674),
new google.maps.LatLng(39.157156, -86.559807),
new google.maps.LatLng(39.160084, -86.553961),
new google.maps.LatLng(39.160317, -86.550700),
new google.maps.LatLng(39.160733, -86.548464),
new google.maps.LatLng(39.161482, -86.546172),
new google.maps.LatLng(39.161536, -86.535107)
];
var pv = new google.maps.Polygon(fairview);
if (google.maps.geometry.poly.containsLocation(myLatlng, pv)) {
console.log("Location Found in Polygon!!!!! " + myLatlng.lat() + " " + myLatlng.lng());
} else {
console.log(":( " + myLatlng.lat() + " " + myLatlng.lng());
}

As Dr. Molle pointed out I was instantiating my polygon incorrectly.
var pv = new google.maps.Polygon({path:fairview});

Related

Getting PidLidEndRecurrenceDate value using Ews

What is the correct way of getting PidLidEndRecurrenceDate values using Ews. below code does not give proper result. property details that i am looking is https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxprops/816378cf-07ef-4926-b7d2-53475792403d
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("X#X.com", "XXX");
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
ItemView view = new ItemView(10);
Guid MyPropertySetId = new Guid("{6ED8DA90-450B-101B-98DA-00AA003F1305}");
int intValue = Convert.ToInt32("0x0000000F", 16);
ExtendedPropertyDefinition extendedPropertyDefinition =
new ExtendedPropertyDefinition(MyPropertySetId, intValue, MapiPropertyType.Integer);
view.PropertySet =
new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, extendedPropertyDefinition);
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, view);
foreach (Item item in findResults.Items)
{
Console.WriteLine(item.Subject);
if (item.ExtendedProperties.Count > 0)
{
// Display the extended name and value of the extended property.
foreach (ExtendedProperty extendedProperty in item.ExtendedProperties)
{
Console.WriteLine(" Extended Property Name: " + extendedProperty.PropertyDefinition.Name);
Console.WriteLine(" Extended Property Value: " + extendedProperty.Value);
}
}
}
That property is set on the Meeting invite messages only not on the Master instance of the Calendar Appointments which is what you seem to be looking at. For the Master instances you should just be able to use the strongly typed property https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.recurrence.enddate?redirectedfrom=MSDN&view=exchange-ews-api#Microsoft_Exchange_WebServices_Data_Recurrence_EndDate
It you wanted to view the property you have above search the SentItems Folder for invites with recurrences (with Enddates) and that's where you will see it. Or probably easier just look at the messages with a Mapi editor like OutlookSpy or MFCMAPI and you will see the properties available.

Leaflet Ajax JSON file Add to Map as Overlay

I have a JSON file that is not formatted in any way to meet geoJson standards. I am trying to load the data I parse from it on the map. I am able to create markers from the data and add them:
$.getJSON( tsdata, function ( data ) {
//loop through all the data
$.each( data.response.docs, function ( key, val ) {
//console.log(val);
if ( typeof val.mc_geo !== 'undefined' ) {
//lat lng isn't consitently 1, so getting the first only.
var geo = val.mc_geo;
var gLat = geo.toString().split( ',' )[ 0 ];
var gLng = geo.toString().split( ',' )[ 1 ];
//add markers to map
var marker = L.marker( [ gLat, gLng ],{icon: tsMarker,} ).bindPopup( "<p><strong><a href='" + val.filename + "'>" + val.title + "</a></strong><hr/><br/><strong>Abstract:</strong> " + truncateString( val.abstract, 350 ) + "</p><p><strong>Author(s): </strong>" + val.author + "<p><strong>Station:</strong> " + val.station_primary_full + "</p>" );
markerArray.push( marker );
}
} );
layer_group = L.layerGroup(markerArray);
map.addLayer(layer_group);
});
This adds the marker layers (layer_group) to the map no problem. However, if I try and add them to the:
L.control.layers(baseMaps, overlayMaps).addTo(map);
I get an error. Basically, L.control.layers is not seeing my layer_group. I can define it before the getJSON call, but L.control.layers will not show the layer full of data though it is "checked" in the layers panel... there are no markers displayed.
How do I dynamically create this marker layer group and have control over it showing (on / off) in my L.control.layers?
It sounds like you add your layer_group to your Layers Control while it is empty ($.getJSON works asynchronously), then re-assign it, so there is no longer a reference between your Layers Control and the markers you have instantiated.
2 easy workarounds:
Add your layer_group to your Layers Control after it is fully built: myLayersControl.addOverlay(layer_group, "Markers")
Use a placeholder Layer Group in your Layers Control, then add your markers into it (myLayerGroup.addLayer(marker)) or simply add your layer_group at the end to it (myLayerGroup.addLayer(layer_group))

Google map as background to my sharpmap map not aligning correctly

I've been at this for quite a while now.
What I'm trying to achieve here is to add Google map as background layer to my Sharpmap, I'm able to achieve this but the problem I'm facing now is My map always centre's to a point near a Greenland sea in Google Map , it's like it won't take my centre point coordinates.
I'm using Sharpmap 1.1 with BruTile 0.7.4.4
So far I've done the below.
SharpMap.Map _map = new SharpMap.Map();
SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("parcel");
SharpMap.Data.Providers.MsSqlSpatial DBlayer = new SharpMap.Data.Providers.MsSqlSpatial(_connectionString, "XXXXXX", "XXXX", "XXX");
layer.Style.Fill = new SolidBrush(Color.Transparent);
layer.Style.Outline = new Pen(Color.Black);
layer.Style.EnableOutline = true;
layer.MaxVisible = 13000;
layer.DataSource = DBlayer;
ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
layer.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
layer.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);
//SharpMap.Layers.TileLayer layerBackground = new TileLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Aerial), "TileLayer");
SharpMap.Layers.TileLayer layerBackground = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), "googlemaps");
_map.Layers.Add(layerBackground);
_map.Layers.Add(layer);
_map.BackColor = Color.White;
//-98.526890,29.411539
_map.Center = new GeoAPI.Geometries.Coordinate(0,0);
return _map;
Even if I manually give Geo Coordinates It just points to the same spot in the sea.
Please see the below Google map Geo point, this is the point where my map shows as centre. Every time I generate no matter what I do it shows this point as its centre.
71.946088, -3.956171
Any help is much appreciated. Thanks and Cheers!
I found the problem for Google map layer not centring.
The reason is that I used QGIS to convert my ESRI shapefile from WGS84(EPSG:4326) format to Spherical Mercator(EPSG:900913) and it changed the coordinates format but
Google Maps use Google Maps Global Mercator (Spherical Mercator).
When I used an online converter to test this out which you can find here. When I gave the resulting coordinates, it worked out just fine. Now all I have to do is find a way to convert Google Maps Global Mercator (Spherical Mercator).
Thanks for your help #pauldendulk.
I was running into the same problem and in theirExamples they provide a LatLongToGoogle transformation function
public static ICoordinateTransformation LatLonToGoogle()
{
CoordinateSystemFactory csFac = new CoordinateSystemFactory();
CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
IGeographicCoordinateSystem sourceCs = csFac.CreateGeographicCoordinateSystem(
"WGS 84",
AngularUnit.Degrees,
HorizontalDatum.WGS84,
PrimeMeridian.Greenwich,
new AxisInfo("north", AxisOrientationEnum.North),
new AxisInfo("east", AxisOrientationEnum.East));
List<ProjectionParameter> parameters = new List<ProjectionParameter>
{
new ProjectionParameter("semi_major", 6378137.0),
new ProjectionParameter("semi_minor", 6378137.0),
new ProjectionParameter("latitude_of_origin", 0.0),
new ProjectionParameter("central_meridian", 0.0),
new ProjectionParameter("scale_factor", 1.0),
new ProjectionParameter("false_easting", 0.0),
new ProjectionParameter("false_northing", 0.0)
};
IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);
IProjectedCoordinateSystem targetCs = csFac.CreateProjectedCoordinateSystem(
"Google Mercator",
sourceCs,
projection,
LinearUnit.Metre,
new AxisInfo("East", AxisOrientationEnum.East),
new AxisInfo("North", AxisOrientationEnum.North));
ICoordinateTransformation transformation = ctFac.CreateFromCoordinateSystems(sourceCs, targetCs);
return transformation;

Geotools - get beside parces

I have a problem needed help. I have parces map layer in postgis which contain polygons. This layer is following by not overlap topology rule.
How could i get features that "beside" a selected feature with geotools api? The "beside" feature is feature have at least one same edge.
For example in this picture, when select feature A, i need to get feature B,C,D, not get feature E.
Any help is high appreciate! Thanks!
I solve my problem by this code
public static void getRoundFeature(SimpleFeature feature, SimpleFeatureSource featureSource){
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
Geometry g = (Geometry) feature.getAttribute("the_geom");
Polygon polygon = geometryFactory.createPolygon(g.getCoordinates());
//Polygon poly = (Polygon) feature;
Filter filter = ff.intersects(ff.property("the_geom"), ff.literal(polygon));
try {
SimpleFeatureCollection featureCollection = featureSource.getFeatures(filter);
//System.out.println("feature around: "+ featureCollection.size());
FeatureIterator iter = featureCollection.features();
while(iter.hasNext()){
SimpleFeature rfeature = (SimpleFeature) iter.next();
System.out.println("so to: "+rfeature.getAttribute("soto")+ "so thua: "+rfeature.getAttribute("sothua"));
}
} catch (IOException e) { LOGGER.log(Level.FINER, e.getMessage(), e);
}
}

Centering Google Maps depending on pins

I have a ASP.NET website which contains a Google Map. I am using the GoogleMapForASPNet framework made by some clever and helpful individual.
Anywho, I have a problem with centering the map after inserting two pins.
Basically, I am calculating the middle point of the pins and setting that as the Center Point of the map.
Below is my code:
GooglePoint newPoint = new GooglePoint();
double newLat = 0;
double newLong = 0;
if (googlePointA.Latitude > googlePointB.Latitude)
{
newLat = googlePointA.Latitude - googlePointB.Latitude;
newPoint.Latitude = googlePointA.Latitude - newLat;
}
else
{
newLat = googlePointB.Latitude - googlePointA.Latitude;
newPoint.Latitude = googlePointB.Latitude + newLat;
}
if (googlePointA.Longitude > googlePointB.Longitude)
{
newLong = googlePointA.Longitude - googlePointB.Longitude;
newPoint.Longitude = googlePointA.Longitude - newLong;
}
else
{
newLong = googlePointB.Longitude - googlePointA.Longitude;
newPoint.Longitude = googlePointB.Longitude + newLong;
}
GoogleMapForASPNet1.GoogleMapObject.CenterPoint = newPoint;
GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 8;
It works half and half, but not properly. As in, when I feed different Pins, it doesn't really center the map, but close enough. Or sometimes, the other pin will be off the map but only an inch, which means the map isn't centered at all.
The zoom is static because the pins will always be close by, so there's no need for me to make it dynamic.
Any help is extremely, extremely, extremely appreciated.
Thank you.
The Google Maps API has an object to do that: google.maps.LatLngBounds
Just create a LatLngBounds object, add your pin coordinates to it with the extend() method, then use the map panToBounds(yourBounds) method and you're all set!